Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-01-03 : 14:58:42
|
| Hii have a field which is float and some values have upto 4 decimal places. i want to round it and use the next upper limiteg:) if it is 1.9015, i need to round it to 1.092if it is 1.0905, i need to round it to 1.091if it is upto 3 decimal places, leave it as its |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-01-03 : 15:42:52
|
| DECLARE @SomeValue FLOATSET @SomeValue = 1.9015SELECT CEILING(@SomeValue*1000)/1000Not tested, but should give you the idea.--Gail ShawSQL Server MVP |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-01-03 : 16:19:03
|
| SELECT ROUND(@SomeValue, 3) also works. |
 |
|
|
jayram11
Yak Posting Veteran
97 Posts |
Posted - 2011-01-03 : 16:58:55
|
| Hello Robvolki initially tried SELECT ROUND(@SomeValue, 3)but it makes 1.0915 into 1.091 but i needed 1.092 and GilaMonster's reply works.ThanksJay |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-01-03 : 17:03:59
|
| Ooops, forgot about the banker's rounding algorithm. |
 |
|
|
BruceT
Yak Posting Veteran
78 Posts |
Posted - 2011-01-04 : 09:23:01
|
| This probably would work also without requiring the multiplication and division.DECLARE @SomeValue FLOATSET @SomeValue = 1.0915SELECT ROUND(convert(numeric(18,4),@somevalue), 3)result = 1.0920 |
 |
|
|
|
|
|