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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Rounding up (& down) numbers with SQL

Author  Topic 

dbchud
Starting Member

13 Posts

Posted - 2010-02-24 : 10:00:52
Hi

Haven't been able to find anything via Google etc, so hoping someone here will have an answer.

Basically I'm trying to round up numbers, for example

what I have what I want
34.50 35.00
233.11 250.00
224.99 200.00
14.22 10.00

etc

Hope that explains what I'm after? Any help is appreciated :o)

Cheers
Gary

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 10:12:33
how did 34.5 got rounded to 35.00 while 14.22 got rounded to 10? then should first case be 30.00?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dbchud
Starting Member

13 Posts

Posted - 2010-02-24 : 10:19:39
Sorry, my mistake - yes, you're correct.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 10:21:46
similarly for both the 200 + values shouldnt rounded value be 200.00?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dbchud
Starting Member

13 Posts

Posted - 2010-02-24 : 10:28:14
Lack of attention on my part - it's late afternoon here, almost time to go home :o)

I'll try again -

I have a requirment to do some calculations, which is fine, then to round up (always up, actually) the number returned. So for 34.5 I'd have to round up to 40.00.

Hopefully I made a bit more sense there?

Gary
Go to Top of Page

dbchud
Starting Member

13 Posts

Posted - 2010-02-24 : 10:33:01
One more example, hopefully I haven't confused anything.

12.44 - I'd like to round this up to 12.5 - would this be possible? :o)

Found this: select round(12.44, 1) but it only rounds down to 12.4.

Cheers
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 10:33:51
Sorry still doesnt make sense . 34.5 should round to 30.00 and not 35.00

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dbchud
Starting Member

13 Posts

Posted - 2010-02-24 : 10:52:51
Ja, agreed - but I need to always round up :o(

This might work out for me:

select round((12.44+.5),0) - will rtn 13.00
select round((12.12+.5),0) - will rtn 13.00

etc

Thanks anyway, appreciated.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-25 : 02:30:03
select ceiling(12.44),ceiling(12.12)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -