Hopefully just a quick question. I have a DECIMAL
column in my database. The value is a very small decimal fraction - summing this value for all rows would equal 1.
Now I'd like to use this value in my php application, display it, perform calculations upon it and save it back to the database.
As php only has integer
and float
types, what is the best way to use that value in php so as not to lose any precision in calculations or display?
- Keep the value as a string and use BC Math for calculations
- Cast the number as
float
- I know php floats are precise to a good number (depending on the OS) - Convert the value to an integer using a function which remembers the exponent
- Something else?
Thanks