Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding to 2 decimal places in SQL

Tags:

every time I want to round to 2 decimal places when it comes to zeros it doesnt want to round it... how could I round it to 2 decimal places with zeros at the end which would give me 92.00 instead of just 92 ???

SELECT ROUND(COLUMN_NAME,2) FROM .... 

it's giving me

COLUMN_NAME 92 

but I want

COLUMN_NAME 92.00 

I used TO_CHAR and it worked

ROUND(TO_CHAR(COLUMN_NAME),2) 

thanks guys!

like image 950
Manual Avatar asked Nov 01 '13 03:11

Manual


People also ask

How do I round to 2 decimal places in SQL Server?

SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places.

How do I get 2 decimal places in MySQL?

SELECT ROUND(-4.535,2); Explanation: The above MySQL statement will round the given number -4.535 up to 2 decimal places.


1 Answers

you may try the TO_CHAR function to convert the result

e.g.

SELECT TO_CHAR(92, '99.99') AS RES FROM DUAL  SELECT TO_CHAR(92.258, '99.99') AS RES FROM DUAL 

Hope it helps

like image 147
Rohan Avatar answered Sep 19 '22 16:09

Rohan