note 38539 added to language.operators.arithmetic

From: Date: Fri, 26 Dec 2003 07:12:10 +0000
Subject: note 38539 added to language.operators.arithmetic
Groups: php.notes 
Request: Send a blank email to php-notes+get-62475@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38539 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38539&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38539&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62475) next »