Sunday, February 19, 2012

convert int to money without decimal and cents

I am doing the following to change an int into money (I want the commas) but it is adding a decimal and 2 zeroes at the end:
convert(varchar,convert(money,m.[FirstTier]),1) as 'First Tier',

m.firsttier = '1583456'
after conversion = '1,583,456.00'

Is there any easy way to not have the '.00'?

Thanks.this trick should do:
parsename(convert(varchar,convert(money,m.[FirstTier]),1),2) as 'First Tier'|||That worked... thanks!
|||Note that PARSENAME returns unicode string so you need to be careful when using that expression in WHERE clause for example. (for example if the column against which you are comparing is indexed and it is varchar , then with this expression the column will be converted to unicode) On the other hand, if this is for display purposes then it is better done in the client-side. Doing it on the client-side, you can handle other regional settings also.

No comments:

Post a Comment