How can I round down if a value is over .5....
Examples:
Normal Rounding: 3.5 to 4
Rounding I need: 3.5 to 3
Normal Rounding: 3.9 to 4
Rounding I need: 3.9 to 3
Originally posted by darknuke How can I round down if a value is over .5.... Examples: Normal Rounding: 3.5 to 4 Rounding I need: 3.5 to 3 ------- Normal Rounding: 3.9 to 4 Rounding I need: 3.9 to 3
well there are 3 rounding functions I know of...
round() -> basic round: 3.4 -> 3 3.5 -> 4
ceil() -> highest number in range: 3.4 -> 4 3.5-> 4
floor() -> lowest number in range: 3.4 -> 3 3.5 -> 3
does that make sense?
simply cast the value as int
$a = (int)$a;
hth
$string = floor(3.5); // output 3 $string = floor(3.9); // output 3 // .. and for future reference $string = ceil(3.5); // output 4 $string = ceil(3.9); // output 4
floor = rounds to the closest lower number ceil = rounds to the closest higher number