Page 1 of 1

Greater boundary....

Posted: Thu May 20, 2004 9:38 am
by pakwai0103
I recently need to deal with the a value that is greater than 14 digits. As we all know, type "double" will only hold up to 14 digits in normal displaying. After that, the value will show in scientific notation like 1.2345678901234E+15. I would like to find out if there are anything that I can do to have the normal value displayed even more than 14 digits, still reamaining in the floating point number type. Thanks.

Posted: Thu May 20, 2004 10:25 am
by jason

still need help

Posted: Thu May 20, 2004 11:09 am
by pakwai0103
jason wrote:Read the part on Size here: http://wiki.devnetwork.net/index.php/FloatType
I know what is floating types do, but my question is how can I get double in normal display value, when it is greater tham 14 digits.

Example: 123456789012345 (what I really want)
1.2345678901235 E+14 ( that is what I getting in PHP)

So, my ultimate question is "How can I avoid the double value turning into the exponential format when it is greater than 14 digits?"...thanks.

Posted: Thu May 20, 2004 11:42 am
by launchcode
Two options - either store it as a string and not a float, or use number_convert on it before you echo the results.

The number you've shown is way beyond a double on a normal 32-bit operating system (maybe on a 64-bit AIX it'd work!), PHP converts to a float the second you assign it outside of a string, which is what it has to do as there is no other way to internally store a value this large - it just isn't how processors work!

The conversion to/from the float however is the downfall. If you just need to display the value, use a string - if you don't need the exact precision, use number_format, if you need to perform math on the value, use the BCMath functions in PHP.