简体   繁体   中英

Round a value to two decimal places in SQL

I am trying to round a value in SQL, here is the code that I have:

select round(600.000,2)

How do I get the value 600.00 ?

Instead of round() convert to a decimal:

select cast(600.000 + 0.5 as decimal(10, 2) )

round() changes the value but it might not change the type of the result. Hence, you might still see extra decimal points (depending on the database and the application). Converting to a decimal with two digits of precision converts both the value and the type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM