Greater boundary....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pakwai0103
Forum Newbie
Posts: 2
Joined: Thu May 20, 2004 9:38 am
Location: Jacksonville, Florida
Contact:

Greater boundary....

Post 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.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

pakwai0103
Forum Newbie
Posts: 2
Joined: Thu May 20, 2004 9:38 am
Location: Jacksonville, Florida
Contact:

still need help

Post 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.
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post 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.
Post Reply