Answers for "rounding the numbers"

7

number round

// There are many ways of rounding...
Math.ceil(5.5) // Answer 6, rounds up.
Math.round(5.5) // Answer 6, rounds to the closest whole number.
Math.floor(5.5) // Answer 5, rounds down.

// ceil is short for ceiling(up), floor is down...
Posted by: Guest on January-06-2022
0

round to nearest step

function round(number, increment, offset) {
    return Math.ceil((number - offset) / increment ) * increment + offset;
}
round(51,  20, 10) // 70
round(70,  20, 10) // 70
round(99,  20, 10) // 110
round(100, 20, 10) // 110
Posted by: Guest on July-19-2021

Code answers related to "rounding the numbers"

Code answers related to "Javascript"

Browse Popular Code Answers by Language