question

Murali avatar image
Murali asked

how to round 2.2875 to 2.29

declare @d decimal set @d='2.2875' select round(@d,0) i need to round it to 2.29...
t-sqldecimalround
10 |1200

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

1 Answer

·
Kev Riley avatar image
Kev Riley answered
There's 2 issues here: 1. you haven't defined the decimal with any precision, so by default is defined as `decimal(18,0)`. When you asign 2.2875 to it, it essentially rounds it, giving 2 2. the second parameter of the `round` function is the number of decimal places to round to. so your code needs to be declare @d decimal (8,2) --for example set @d='2.2875' select round(@d,2) gives 2.29
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.

Murali avatar image Murali commented ·
thank you...
0 Likes 0 ·

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.