SQL Server - Round fn in Sql server 2008 - Asked By Anandh Ramanujam on 16-Dec-11 09:01 AM

Hi,

How to round this number 123.6789232 to 123.68 in sql server

Thanks.
Riley K replied to Anandh Ramanujam on 16-Dec-11 09:34 AM


Use this 

SELECT ROUND(@value, 2)


Regards
Anandh Ramanujam replied to Riley K on 16-Dec-11 09:36 AM
thats give the result as

123.68000

but i want the result to be 123.68
Riley K replied to Anandh Ramanujam on 16-Dec-11 09:40 AM


Here is it

Declare @invTax Money
SET @invTax=123.6789232
select convert(decimal(12,2),@invTax)


Output

123.68
Anoop S replied to Anandh Ramanujam on 17-Dec-11 01:58 AM
you should not use ROUND in this case, if we use round number of decimal places will be same as original number, for eg

number 2.65865, if we round this ->  ROUND(2.65865,2)  output will be 2.66000

so use convert like this way
select convert(decimal(12,2),2.65865)
O/P -> 2.66

Chintan Vaghela replied to Anandh Ramanujam on 17-Dec-11 02:27 AM

Hello,

Try following way

 

SELECT CAST(ROUND(123.4567, 2) AS MONEY)

SELECT CONVERT(Money,ROUND(123.4567,2))

 

SELECT CONVERT(DECIMAL(25,2),ROUND(123.4567,2))

SELECT CAST(ROUND(123.4567, 2) AS Decimal(25,2))

 

 

Hope this is helpful !

Thanks

 

 

 

 

 

Sunil Darji replied to Anandh Ramanujam on 17-Dec-11 04:06 AM


select convert(decimal(18,2),round(123.6789232,2))
udhayaganesh pachiyappan replied to Sunil Darji on 19-Dec-11 02:09 AM

select cast(123.6789232 as numeric(18,2)) as value

select cast(123.6789232 as decimal(18,2)) as value