note 38539 deleted from language.operators.arithmetic by nlopess

From: Date: Fri, 26 Dec 2003 09:41:40 +0000
Subject: note 38539 deleted from language.operators.arithmetic by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62483@lists.php.net to get a copy of this message
Note Submitter: Mike G ---- If you really need to use a float you can always use one of these. <?php $dividend = 48; $divisor = 1.25; $divisor *= 100; $dividend *= 100; print $dividend % $divisor / 100; //returns 0.5 as expected ?> Or if you want to be complicated or don't want to use too many 0s or too few 0s (i.e. you can multiply by 10000000 for a float like 1.0000025) <?php $dividend = 48; $divisor = 1.25; $eds = explode('.', "$divisor"); $ch = strlen($eds[1]); $value = pow(10, $ch); $divisor *= $value; $dividend *= $value; print $dividend % $divisor / $value; //returns 0.5 as expected ?> I tested both and they both work nicely.

« previous php.notes (#62483) next »