I have a function that adds a lot of numbers with decimals…. FLOAT numbers from MySQL DB.
Right now, I have the issue that sometimes they will add to ridiculously small numbers like -1.11022302463E-16, instead of zero. Any ideas?
By the way,
All my numbers I’m adding are monetary, so they are all like : XXX.XX ….
Thanks
As suggested by @BoltClock, change all the
floatfields todecimal(10,2)fields in your database where they are used for monetary values.Float suffers from rounding problems like the ones you describe.
If you do all your adding inside the database you will not suffer any rounding errors.
You can add numbers by doing a
Substituting the constants for parameters.