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 2008 Forums
 Transact-SQL (2008)
 Real Data Types

Author  Topic 

ibbo14
Starting Member

10 Posts

Posted - 2013-02-07 : 21:15:42
Hi,

I was hoping that someone would have a solution to a problem that I have just encountered. I am migrating data from one system to another, and in the source DB, the decimal type data is specified as real. The destination DB is using float. I have been using select insert statements, and the real data type fields were appearing as rounded. After completing the migration I realized that this is not the case.

An example: It appears in the source db using the real data type as -58.6

When using float it appears as: -58.5999984741211

Is there a way to fix this without remigrating the data. The catch is that the number of decimal places can vary.

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-07 : 23:15:19
if you want values up to definite decimal place only stored in table, you need to use fixed numerical datatypes like Numeric of Decimal. float,real are approximate datatypes.

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

Go to Top of Page

ibbo14
Starting Member

10 Posts

Posted - 2013-02-08 : 00:01:10
Thanks for the response visakh

In my case the number of decimal places can vary, this is why I chose float as the destination data type. So rounding may not be an option.

I have been digging deeper and have tried the approach of converting the real value to varchar and then to float. It seems to work, but something is telling me not to trust this.

Or am I being a bit too cautious?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-08 : 03:25:42
quote:
Originally posted by ibbo14

Thanks for the response visakh

In my case the number of decimal places can vary, this is why I chose float as the destination data type. So rounding may not be an option.

I have been digging deeper and have tried the approach of converting the real value to varchar and then to float. It seems to work, but something is telling me not to trust this.

Or am I being a bit too cautious?


in that case you can use round where value will be rounded to required decimal place

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

Go to Top of Page
   

- Advertisement -