SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Real Data Types
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ibbo14
Starting Member

Australia
7 Posts

Posted - 02/07/2013 :  21:15:42  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 02/07/2013 :  23:15:19  Show Profile  Reply with Quote
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

Australia
7 Posts

Posted - 02/08/2013 :  00:01:10  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 02/08/2013 :  03:25:42  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000