Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rounding off to two decimal places in SQL

Tags:

sql

rounding

People also ask

How do you round off decimals after SQL?

Decimal data type value with positive LengthSELECT ROUND(@value, 1); SELECT ROUND(@value, 2); SELECT ROUND(@value, 3); In this example, we can see that with decimal values round up to the nearest value as per the length.

How do I round a number in SQL?

In Oracle, MySQL, and PostgreSQL, you can use either the CEIL() or CEILING() function to round up.


You could cast your result as numeric(x,2). Where x <= 38.

select
    round(630/60.0,2),
    cast(round(630/60.0,2) as numeric(36,2))

Returns

10.500000    10.50

With SQL Server 2012, you can use the built-in format function:

SELECT FORMAT(Minutes/60.0, 'N2')

You can use:

select cast((630/60.0) as decimal(16,2))

in SQL Server


Declare @number float = 35.44987665;
Select round(@number,2)