简体   繁体   中英

How can I round a value in SQL

How can I round a value in SQL, used round function .actual result is 555.81 getting 555 script is round(expression,0)

this is the result which I used round(expression,2) when I use round(expression,0) getting 555 as answer

问题图片

ROUND documentation on MSDN

select
  [raw]       = 555.81, 
  [rounded]   = round(555.81, 0),
  [truncated] = round(555.81, 0, 1)

Result:

|    raw | rounded | truncated |
|--------|---------|-----------|
| 555.81 |     556 |       555 |

SQL Fiddle: http://sqlfiddle.com/#!6/9eecb7db59d16c80417c72d1/5290

I believe it is rounding down. round(expression+0.5,0) Should work but I have not tested it.

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