L
Lance Hoffmeyer
Hey all,
I want to round numbers with one decimal place.
I know one can round in this manner:
sub round {
my($value) = shift;
return int($value + .5);
}
What I now need to add to this if that if a number is exactly
??.5 and is an even number then round down (i.e. 22.5 = 22)
and if a number is odd and ??.5 then round up (i.e. 21.5 = 22).
How can I test whether a number is even or odd?
sub round {
if ($value = "??.5 and even){ $value = $value - .1};
if ($value = "??.5 and odd"){ $value = $value + .1};
my($value) = shift;
return int($value + .5);
}
I want to round numbers with one decimal place.
I know one can round in this manner:
sub round {
my($value) = shift;
return int($value + .5);
}
What I now need to add to this if that if a number is exactly
??.5 and is an even number then round down (i.e. 22.5 = 22)
and if a number is odd and ??.5 then round up (i.e. 21.5 = 22).
How can I test whether a number is even or odd?
sub round {
if ($value = "??.5 and even){ $value = $value - .1};
if ($value = "??.5 and odd"){ $value = $value + .1};
my($value) = shift;
return int($value + .5);
}