Abstract
In this example we are going to show you several techniques to round up, round down and round to nearest, currencies or any value you are managing.

When you are selling retail products, sometimes you don’t want to use prices ending with a given “cents part” or you need to force the ending or the price in “.95” or “.99” which could be “more commercial”

Let’s go with that rounding
First of all, we are going to round a decimal value to the next highest integer value by rounding up, using ceil function.

$value = ceil(4.3);   // returns 5
$value = ceil(9.999); // returns 10
$value = ceil(1.04);  // returns 2

Now, using floor function, we are going to round a decimal value to the next lowest integer value by rounding down.

$value = floor(4.3);   // returns 4
$value = floor(9.999); // returns 9
$value = floor(1.04);  // returns 1

And now, a built in function called CFO_RoundUpNearest (included in CFO) which will help you to round up to the next multiplo of value.

$value = CFO_RoundUpNearest(4.3, 5);    // returns 5
$value = CFO_RoundUpNearest(9.999, 10); // returns 10

This function is useful to round, for example, to real currency decimals.

$value = CFO_RoundUpNearest(1.04, 0.05); // returns 1.05
$value = CFO_RoundUpNearest(1.14, 0.05); // returns 1.15
$value = CFO_RoundUpNearest(1.29, 0.05); // returns 1.30