Re: Problem with calculate
| From: | Rosen | Date: | Fri, 16 Jul 2004 21:02:38 +0000 |
| Subject: | Re: Problem with calculate | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190764@lists.php.net to get a copy of this message | ||
Thanks !
abs() will not work for me, because I may have na negative numbers, but with
round() it worked !
10x
"John W. Holmes" <holmes072000@charter.net> wrote in message
news:40F83F0A.6000501@charter.net...
> Rosen wrote:
>
> > I use some numbers from mysql table and other local vars to calculate
one
> > number.
> > But on one calc I receive thath $value=4.5474735088646E-013;
> > This must be zero (0) - I see all vars and calc then with calculator. I
use
> > function number_format($value, 2, ".", "" ) and it return me -0.00
>
> When you use floating point numbers, you can get small errors like this.
> To the computer, 4.54E-13 is about the same as zero. number_format()
> returns the correct result... well, the negative sign may throw you off.
> You can use abs() and round() to get what you want, more than likely.
>
> The thing to remember and react accordingly to is that for floating
> point numbers, 2.0 - 1.5 can equal 0.4999999999999999 and be "correct"
> because of the precision.
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals www.phparch.com