Re: Modulus and floating point...

From: Date: Fri, 04 Jan 2002 19:43:28 +0000
Subject: Re: Modulus and floating point...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-79489@lists.php.net to get a copy of this message
You can consider doing this: $number=102.52; $fraction=$number-floor($number); $number=($number % 50)+$fraction; Basically it's the exact solution you're suggesting, just that you don't have to do any string stuff. PHP's behaviour is normal - modulus is generally intended for integers... Bogdan "Boget, Chris" wrote: > Consider the following: > > $number = 102.52; > > echo $number % 50; > echo bcmod( $number, 50 ); > > in both cases, it's spitting out "2". Why is it not spitting > out "2.52"? Is there a way I can get that information? > w/o having to parse the string, breaking it up, getting > the modulus and then adding it back into the end result...? > > Chris

« previous php.general (#79489) next »