note 71403 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:06:06 +0000 |
| Subject: | note 71403 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189810@lists.php.net to get a copy of this message | ||
Note Submitter: jon_rhoades at yahoo dot com
----
Jonathon Reinhart's neat little function to find out if a value is odd or even doesn't
work for floats (this might possibly arithmetically correct but causes the following problem) eg
<?php
12.23 % 2 = 0 not 1
?>
So if you need to find out if the fraction part of a float is odd or even try:
<?php
if (($a /2) != (floor($a /2))){
echo "$a is odd." ;
}
if (($a /2) == (floor($a /2))){
echo "$a is even." ;
}
?>