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.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

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

if possible, change the datatype to "decimal" which, unlike "float" and "real", is not an approximate data type.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

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.
RadhaKrishnaKiJayaAuthor Commented:
Is there anyway I can store the real value and get it as it is without any change?

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.
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

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.
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.