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.
Thanks.
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"),
Thanks.
ASKER
What should I do to get the correct number.
Thanks.
Thanks.
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.
ASKER
Is there anyway I can store the real value and get it as it is without any change?
Thanks.
Thanks.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank u.
http://sqlmag.com/sql-server/tip-when-real-not-real
Hope this clarifies things !