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
 Mathematical operations in Sql server 2005

Author  Topic 

aditya2010
Starting Member

10 Posts

Posted - 2010-04-12 : 20:21:02
Hi,

I need some help with decimals rounding.

Ex:if i have a decimal value of 10.45 or anything less than 10.50 then i need to return 9.99 as ouput decimal otherwise say if the value is more than 10.50 then i need to return 10.99.Its very urgent.

Please suggest me.
Thanks.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-12 : 20:23:40
Use the ROUND function and then subtract 0.01 with DATEADD function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-12 : 20:24:48
quote:
Originally posted by aditya2010

Its very urgent.



How come?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

aditya2010
Starting Member

10 Posts

Posted - 2010-04-12 : 21:53:08
Hi thanks for replys.I did do some logic around there instead using round function.Get the decimal part
Added a codition to see if the deciaml part is less than or greater than 0.5 then wrote some logic to
to get my desired value.

But noe i need some other help,after getting the desired value from the above thread say 9.99 or 10.99 ,i am doing a mathematical function.
Say 10.99/1.1----9.9909090 this is the result i am getting.Because the desired value is money type.Now i need some help ,i want to get the value 9.9909090 as 9.99 wihtout rounding.
Please suggest me a way.
Thanks.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-12 : 22:09:45
You can convert it to DECIMAL(18,2), which will give you two decimal places. Use the CONVERT function for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-12 : 22:31:39
quote:
Originally posted by tkizer

Use the ROUND function and then subtract 0.01 with DATEADD function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



DATEADD function ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-12 : 22:34:15
Oops! I had two topics I was looking at, must've mixed them together (the other was the dateadd/business day topic you answered). Haha!

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-12 : 22:35:10
LOL multi-tasking bug


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2010-04-13 : 08:30:05
quote:
Originally posted by aditya2010

I need some help with decimals rounding.

....Its very urgent.



quote:
Originally posted by tkizer


How come?


He works for NASA and the lander will be entering the planet's atmosphere at any time now.

________________________________________________
If it is not practically useful, then it is practically useless.
________________________________________________
Go to Top of Page
   

- Advertisement -