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
 problem with Converting Money to String

Author  Topic 

ZarrinPour
Yak Posting Veteran

66 Posts

Posted - 2008-05-05 : 22:06:15
Hi
there is something strange in the code below:

declare @a money
set @a=1.2365
print cast(@a as varchar(10))

when i run the code in the query analizer , the output will be rounded and always will be displayed with two decimal digits(=1.24)...why?
how can i move the whole number value as an string value to an string variable without this truncation?

Thanks.
kind Regards.

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-05-05 : 23:04:05
The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent. If you like to see whole number, you can cast it to decimal.
Go to Top of Page

Anoop
Starting Member

6 Posts

Posted - 2008-05-06 : 04:04:25
Money data type will always round upto 2 decimal point. If you want to use decimal, try this.

declare @a decimal(10,4)
set @a=1.2365
print cast(@a as varchar(10))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-06 : 04:57:28
I thought that depended on locale settings.
declare @a money
set @a = 1123.2365

print cast(@a as varchar(10))
print str(@a , 10, 4)
print ''
print convert(varchar(10), @a, 0)
print convert(varchar(10), @a, 1)
print convert(varchar(10), @a, 2)
print convert(varchar(10), @a, 3)



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -