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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 rounding numbers

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-04-10 : 12:20:16
i have following sample

create table table1
(id int identity(1,1)
,value1 float --varchar(10) --decimal(8,3)
)

insert into table1
select '1.22' union all
select '1.45' union all
select '0.67' union all
select '2.04' union all
select '2.106' union all
select '11.091'


i want value1 to be rounded (up or down) as following:
1.22 -> 1.20 (down)
1.45 -> 1.45 (no change)
0.67 -> 0.70 (up)
2.04 -> 2.05 (up)
2.106 -> 2.10 (down)
11.091 -> 11.10 (up)

thanks

DBA in the making
Aged Yak Warrior

638 Posts

Posted - 2010-04-10 : 14:41:39
0.67 -> 0.70 (up)

Is that correct? I would have though down to 0.65. If that's the case, then this will give you that:
ROUND(value1 * 20.0, 0) / 20.0


However, if 0.70 is correct, then you're going to have to specify exactly where the rounding points are, and the solution will be more complex.

------------------------------------------------------------------------------------
Any and all code contained within this post comes with a 100% money back guarantee.
Go to Top of Page
   

- Advertisement -