Jump to content

Why data type REAL returns almost-correct values for decimals?


Recommended Posts

MS SQL Server - data type "real"


I add a value of 95.4, and that's what displays in the SQL table, but when I fetch the value via PHP, I get 98.400002. Other values:


98.2 = 98.199997

98.3 = 98.300003

98.4 = 98.400002

98.5 = 98.5

98.6 = 98.599998

98.7 = 98.699997

98.8 = 98.800003

98.9 = 98.900002




I can use round to fix it, but would rather fix the problem than the symptom.





Link to comment
Share on other sites

Why is it one value in one place and something else in another?


Not all software treats floats the same way.  Some software may use more or less bits to represent the value, or may have different levels of precision/rounding.  There's a whole slew of problems/quirks one has to deal with when working with floating point values.  That is why it is generally recommended you avoid them when possible.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.