function roundToNickle($value) {
// multiply the value by 100
// for some reason value%.05 gives a divide by zero error
$value *= 100;
// get remainder of value / 5
$remain = $value % 5;
if ($remain < 2.5) {
// round down by subtracting the remainder
$value -= $remain;
} else {
// round up by adding difference between 5 and remainder
$value += (5-$remain);
}
// round it off just to be safe
$value = round($value);
// divide by 100 to get back to a decimal amount
$value /= 100;
return $value;
}
ASKER
ASKER
ASKER
ASKER
0.186666666667 becomes 0.19 <-- correctSomething like
0.08 becomes 0.08 <-- correct
0.106666666667 becomes 0.11 <-- correct
0.24 becomes 0.25 <-- wrong (should stay the same value)
0.48 becomes 0.49 <-- wrong (should stay the same value)
0.32 becomes 0.32 <-- correct
my original problem (the main question).To help you any further we need to see the SSCCE. In this case that would be a set of input values and the expected outputs, along with the rules you want to apply to transform the inputs into the outputs. A two column layout of the inputs and the corresponding expected outputs would suffice. Please post that here, and I'll try to help you make sense of it.
ASKER
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY