whole number/division/modulus?
Posted: Mon Dec 15, 2003 10:41 pm
I have an array, I want to check for errors before placing in my db.
Now, these values can only have possible values of x.25, x.50, x.75 , x.00 or x. so I want to do a foreach loop through the array and determine if any of these values doesn't meet that criteria. Such as the 3rd item above ( [E022] => 1.16 ].
I've tried several different approaches including:
Which didn't work, well I don't know why, maybe because the values are strings? also the modulus (%) doesn't seem to work with decimals.
I also tried:
Which didn't work either, I think because a division operator automatically makes it a double or float.
If anyone can clue me in, I'd appreciate it.
-Garrett
Code: Select all
їdata] => Array
(
їE001] => 40.00
їE021] => 2.25
їE022] => 1.16
їE01S] => 0.00
їE012] => 0.00
їE09B] => 0.00
)I've tried several different approaches including:
Code: Select all
foreach( $_POSTї'data'] as $k => $v ) {
if ( ($v % .25) > 0 ) {
$site->raise_error( 'All data must be either .25, .50, .75, .00' );
}
}I also tried:
Code: Select all
foreach( $_POSTї'data'] as $k => $v ) {
$v = $v / .25;
if ( is_double($v) ) {
$site->raise_error( 'All data must be either .25, .50, .75, .00' );
}
}If anyone can clue me in, I'd appreciate it.
-Garrett