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
 Cast functions

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2012-03-27 : 13:56:51
I have a field with a value of 35.156

price = 35.156

If I do:

cast(price as decimal (16,2)) it rounds and gives me 35.16 which I don't want. I want 35.15.

If I do:
cast(price as decimal (16,3)) it returns : 35.156

Is there a way I can stop this from rounding or hack off the 6 from the 2nd example?

I'm dealing with multiple records and values so subtracting .006 will not work for me.

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-27 : 13:58:56
what's the datatype of your "field"? varchar?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2012-03-27 : 13:59:38
decimal(16,6)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-27 : 14:02:57
DECLARE @x varchar(26); SET @x = '35.156'

SELECT CAST(LEFT(@x,5) AS decimal(15,2))

??

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-27 : 14:58:46
why are you opening multiple threads for same issue?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=173011

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=173006

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

Go to Top of Page
   

- Advertisement -