Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya

asked on

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.

Avatar of Sylvain Drapeau
Sylvain Drapeau
Flag of Canada image

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

Hope this clarifies things !
Avatar of RadhaKrishnaKiJaya


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.
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.
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.
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank u.