question

sagar 2 avatar image
sagar 2 asked

Sql round off values

Hello i am using a query which outputs values like this: 589.65 236.88 I used "CEIL" function to round them off, But it is showing as 560 237 I want the output as: 560.00 237.00
sql
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
not sure how to round 589.65 to 560, but presume that's a typo!!
2 Likes 2 ·
Kev Riley avatar image
Kev Riley answered
try select ROUND(236.88,0) gives 237.00 `ROUND` returns the same datatype as passed in when the expression is decimal(p,s) ---- **edit** : OP has confirmed that the requirement is to round UP, but maintain the decimal places. One possibility if you know what the datatype is, is to cast the result of the CEILING (which is an integer) back to that datatype: select cast(ceiling(80585.27) as decimal(8,2)) gives 80586.00
3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sagar 2 avatar image sagar 2 commented ·
I tried ROUND function. I want to convert 80585.27 to 80586.00,But round function rounds it to 80585.00
0 Likes 0 ·
Kev Riley avatar image Kev Riley ♦♦ commented ·
@sagar, I've updated my answer
0 Likes 0 ·
sagar 2 avatar image sagar 2 commented ·
Thank you>>
0 Likes 0 ·
Håkan Winther avatar image
Håkan Winther answered
SQL server shouldn't need to bother about formatting, such things should be handled I the GUI.
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Fatherjack avatar image Fatherjack ♦♦ commented ·
+1 - definitely a unicorn
4 Likes 4 ·
Matt Whitfield avatar image Matt Whitfield ♦♦ commented ·
+1 - definitely a UI concern
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.