Real data type value getting changed when reading thru a datareader

Hi Experts,

I have a value 11.11  in the sql server table. Its data type is real. But when I read it using sql datareader , Reader.Item("Commission"), I am getting a different value 11.1099996566772. What could be the reason.

Thanks.
RadhaKrishnaKiJayaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SylvainDrapeauCommented:
Not all numbers are precisely represented, please read this article to better understand the matter :

http://sqlmag.com/sql-server/tip-when-real-not-real

Hope this clarifies things !
1
RadhaKrishnaKiJayaAuthor Commented:
What should I do to get the correct number.

Thanks.
0
SylvainDrapeauCommented:
if possible, change the datatype to "decimal" which, unlike "float" and "real", is not an approximate data type.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

SylvainDrapeauCommented:
Also note, it's not the DataReader that changes the value, it's the way the value is stored. When you store "11.11" in as a real, what is stored is an approximation of that number, which is returned when you read it through the DataReader.
0
RadhaKrishnaKiJayaAuthor Commented:
Is there anyway I can store the real value and get it as it is without any change?

Thanks.
0
SylvainDrapeauCommented:
Only way I see is rounding the value to the amount of decimal you need, which may not be a good idea depending on what exactly those numbers represent and how they are used afterward. You should not store them as real if they need to be retrieved exactly as entered.
1
MlandaTCommented:
If you know you were only saving to an accuracy level of two decimal points, rounding is the best option.

SELECT ROUND(column_name,decimals) FROM table_name;

That said, it's going to be best to think your data type choice. If these are currency figures, a deviation on 0.001 might sound trivial for most, but not when the figure represents a billion dollars. Consider the use of decimal, currency, and numeric data types
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadhaKrishnaKiJayaAuthor Commented:
Thank u.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.