What are Roundup, Rounddown, Modulo, Ceiling Functions?
1 Like
1. Roundup Function
- Purpose: Rounds a number up to the nearest integer or specified number of decimal places.
- Behavior: Always rounds away from zero, regardless of the decimal value.
- Example:
Roundup(4.2)โ 5Roundup(-4.2)โ -5Roundup(3.14159, 2)โ 3.15 (rounds up to 2 decimal places)
2. Rounddown Function
- Purpose: Rounds a number down to the nearest integer or specified number of decimal places.
- Behavior: Always rounds towards zero, regardless of the decimal value.
- Example:
Rounddown(4.8)โ 4Rounddown(-4.8)โ -4Rounddown(3.14159, 2)โ 3.14 (rounds down to 2 decimal places)
3. Modulo Function
- Purpose: Returns the remainder after dividing one number by another.
- Behavior: If
xis divided byy, the result is the remainder ofx / y. - Formula:
Modulo(x, y) = x - (y * floor(x / y)) - Example:
Modulo(10, 3)โ 1 (10 รท 3 = 3 remainder 1)Modulo(-10, 3)โ -1Modulo(10, -3)โ 1
4. Ceiling Function
- Purpose: Rounds a number up to the nearest integer or specified multiple.
- Behavior: Similar to
Roundup, but focuses on the nearest multiple of a value. - Example:
Ceiling(4.2)โ 5Ceiling(-4.2)โ -4Ceiling(4.2, 0.5)โ 4.5 (rounds up to the nearest 0.5 multiple)
1 Like
In this case What is the differenece between roundup/ceiling and rounddown/floor? and in which we have to use these all four?