[PHP] Modulus and floating point...
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
Re: [PHP] Modulus and floating point...
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Modulus Formatting
Hi Michael, Use a temporary variable [counter], if counter%3 == 0 then write /trtr in the output. $counter=0; print "tr"; while($row = mysql_fetch_array($result)) { echo "td".$row["user_id"]."/td"; $counter++; if (!$counter%3) { echo "/trtr"; } } That's all ;-) Ahmad Anvari - Original Message - From: Michael Hall To: PHP List Sent: Tuesday, February 06, 2001 10:03 AM Subject: [PHP] Modulus Formatting I can pull data out of a database using mysql_fetch_array and assemble it like this using a while statement: TRTD$data/TD/TR TRTD$data/TD/TR TRTD$data/TD/TR etc ... What I'd like to do is assemble it like this: TRTD$data/TDTD$data/TDTD$data/TD/TR etc... In other words, I need a break (/TRTR) every three times through the loop. I've tried several snippets of code from this list's archive but none seem to work. I've tried while statements, for statements and the list function in every combination I can think of ... no go. I know that modulus is what I need but I can't crack the right code combination. Does anyone have a solution or can they point me to a resource somewhere? Thanks Mick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Modulus Formatting
I can pull data out of a database using mysql_fetch_array and assemble it like this using a while statement: TRTD$data/TD/TR TRTD$data/TD/TR TRTD$data/TD/TR etc ... What I'd like to do is assemble it like this: TRTD$data/TDTD$data/TDTD$data/TD/TR etc... In other words, I need a break (/TRTR) every three times through the loop. I've tried several snippets of code from this list's archive but none seem to work. I've tried while statements, for statements and the list function in every combination I can think of ... no go. I know that modulus is what I need but I can't crack the right code combination. Does anyone have a solution or can they point me to a resource somewhere? Thanks Mick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Modulus
Hi Mike! On Thu, 25 Jan 2001, Mike P wrote: I know i'm a liitle slow but why does 2%4 = 2 and not 0 or 1 cause 4*0+2=2 thanks Mike [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- teodor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Modulus
4%2 = 0 4 div 2 equals remainder 0 2 div 4 doesnt divide so your left with the remainder equal to what you started with, 2 -- Chris Lee Mediawaveonline.com [EMAIL PROTECTED] ""Mike P"" [EMAIL PROTECTED] wrote in message 94qjq0$rde$[EMAIL PROTECTED]">news:94qjq0$rde$[EMAIL PROTECTED]... I know i'm a liitle slow but why does 2%4 = 2 and not 0 or 1 thanks Mike [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]