Re: Loss of precision in intval()

From: Date: Wed, 08 Aug 2007 03:29:16 +0000
Subject: Re: Loss of precision in intval()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-260404@lists.php.net to get a copy of this message
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?

« previous php.general (#260404) next »