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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 converting a datatype from float to money

Author  Topic 

PeterG
Posting Yak Master

156 Posts

Posted - 2002-08-22 : 13:54:19
I have this table with one column having a float datatype. This was an oversight and I want to correct it by converting it to money, as the data for this field is money. All the records in the table for this field have either one decimal or two decimals. I am not sure if there is going to be a problem or not after conversion. Will you enlighten me on this guys? Is there another (or better) way of doing this?

P.S. The reason to convert is that selecting a larger amount like 18789.53 would return 18789.5.

Kevin Snow
Posting Yak Master

149 Posts

Posted - 2002-08-22 : 15:34:20
During the conversion, the float value gets rounded to 4 decimal places. This can be a problem if you are dealing with numbers around, say , 1 trillion. You may also see problems if the float is a calculated value (has decimal value beyond 1/10000th of a dolar) and the rounding scheme differs from the one you want.

ex
Declare @f float,@m money
set @f=18854.40
select @f
set @m=convert(money,@f)
Select @m

Where you have only one or two decimals, and the dollar amounts are relatively low, you should have few problems. It's worth checking the rounded values against the expectations of any applications using the data. There are various rounding schemes that may come into play, and if they use one that is different from that of the conversion, you will see occasional differences of a penny.


Go to Top of Page
   

- Advertisement -