Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- adding numbers in php
- Sander Peters
October 26, 2005, 1:44 pm
rate this thread
I have the following situation:
I will get the value '14.5' back from PHP.
Wich is logical.
But what I want is to get the value '14.5000'.
Is there somehow a workaround to let PHP print 4 decimals?
Thanks in advance for your reaktion.
Re: adding numbers in php
Maybe. I'm sure you will shortly be coming up against the NEXT surprising
truth about floating point values, and that is that 5.6 and 8.9 cannot be
represented exactly in binary. Just like trying to represent 1/3 in
decimal, values like 5.6 and 8.9 requires an infinite number of bits. So,
the value you actually get is only an approximation.
Because of that, 5.6 + 8.9 does not actually equal 14.5 (which CAN be
represented exactly in binary). It will PRINT as 14.5, because printing
rounds it, but if you do this:
if( $c == 14.5 )
it will not actually print "yes".
- Tim Roberts, email@example.com
Providenza & Boekelheide, Inc.
- » exec, shell_exec, system, and passthru not working at all
- — Previous thread in » PHP Scripting Forum