Re: Loss of precision in intval()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, August 1, 2007 11:52 am, Mark Summers wrote:
> This sort of thing really isn't helpful...
>
> <?php
>
> $a = 75.82 * 100;
>
> echo intval($a);
>
> ?>

What did you get?
What did you expect?

Do you have ANY idea how floats are actually represented internally in
every computer language? [*]

If you expect to have a specific precision, then you need to write
code to have that precision.

For simple "money" just use cents instead of dollars and keep
everything as an int except for final output.

For anything more complicated, you have http://php.net/gmp or, in lder
versions of PHP, BC Math.

* Yeah, okay, there ARE languages where 75.82 really IS 75.82 and not
some close approximation...  But they are pretty esoteric languages,
really.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux