Friday, February 24, 2012

convert money datatype

Hello!

I need to convert money datatype into string without decimal points.

For example, I have column pmt_amt (money datatype)=27.00.

Is there a way to convert this amount into format "2700" without decimals?

Thanks,

Lena

Can you do that in the presentation layer?

declare @.m money

set @.m = 27

select @.m, str(@.m * 10000, 15, 0)

set @.m = 27.0015

select @.m, str(@.m * 10000, 15, 0)

AMB

|||

Thank you!

I tried your conversion and here's my results:

value in table converted

47.02 470200 1202.78 12027800 411.91 4119100 20401.78 204017800 711.01 7110100 517.83 5178300 11756 117560000 773 7730000 3439.75 34397500 4062.66 40626600

How can I get rid of zeroes in the end of converted values?

E. G.: for 40626600 I need it t be 406266.

|||

I would 'refine' AMB's suggestion with the following:

If you want the results to have ONLY 2 numbers to the right of the decimal, then use 100 instead of 10000 in the str() function. That is because the money datatype has four (4) numbers to the right of the decimal, and EVEN though you often ignore them, they are there.

(It will still round up/down as needed.)

And if you have really large numbers, the '15' in the string function may need to be increased.

|||

Money data type has 4 decimal digits. If you want to consider just the first two, then multiply the value by 100 instead 10000.

declare @.m money

set @.m = 4062.66

select @.m, str(@.m * 100, 15, 0)

AMB

|||

Thank you for all your replies.

It helped a lot.

No comments:

Post a Comment