🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › ceil
Math.ceil() - JavaScript | MDN
Math.ceil(-Infinity); // -Infinity Math.ceil(-7.004); // -7 Math.ceil(-4); // -4 Math.ceil(-0.95); // -0 Math.ceil(-0); // -0 Math.ceil(0); // 0 Math.ceil(0.95); // 1 Math.ceil(4); // 4 Math.ceil(7.004); // 8 Math.ceil(Infinity); // Infinity ... This page was last modified on Jul 10, 2025 by ...
🌐
WebPlatform
webplatform.github.io › docs › javascript › Math › ceil
ceil · WebPlatform Docs
javascript · Math · ceil · Returns the smallest integer greater than or equal to its numeric argument. Math.ceil( number ) Math.ceil(0.4); // 1 Math.ceil(1.9); // 2 Math.ceil(3); // 3 · The required number argument is a numeric expression. The return value is an integer value equal to the ...
🌐
GitHub
github.com › mdn › content › blob › main › files › en-us › web › javascript › reference › global_objects › math › ceil › index.md
content/files/en-us/web/javascript/reference/global_objects/math/ceil/index.md at main · mdn/content
The **`Math.ceil()`** static method always rounds up and returns the smallest integer greater than or equal to a given number. ... The smallest integer greater than or equal to `x`. It's the same value as [`-Math.floor(-x)`](/en-US/docs/Web...
Author   mdn
🌐
W3Schools
w3schools.com › jsref › jsref_ceil.asp
JavaScript Math ceil() Method
new Map clear() delete() entries() forEach() get() groupBy() has() keys() set() size values() JS Math · abs() acos() acosh() asin() asinh() atan() atan2() atanh() cbrt() ceil() clz32() cos() cosh() E exp() expm1() f16round() floor() fround() LN2 LN10 log() log10() log1p() log2() LOG2E LOG10E max() min() PI pow() random() round() sign() sin() sinh() sqrt() SQRT1_2 SQRT2 tan() tanh() trunc() JS Numbers
🌐
GitHub
gist.github.com › vpodk › c2ad215e1021a16fd3e1
Manipulating numbers in JavaScript. · GitHub
Manipulating numbers in JavaScript. Raw · numbers.js · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters · Show hidden characters · Copy link · Wrong logic in Math.ceil - Will not act like is should for integer values: console.log(Math.ceil(1) == ~~1 + 1) // 1 == 2 ·
🌐
Programiz
programiz.com › javascript › library › math › ceil
JavaScript Math ceil()
Become a certified JavaScript programmer. Try Programiz PRO! ... The ceil() method rounds a decimal number up to the next largest integer and returns it. That is, 4.3 will be rounded to 5 (next largest integer). let number = Math.ceil(4.3); console.log(number); // Output: 5
🌐
Math.js
mathjs.org › docs › reference › functions › ceil.html
math.js | an extensive math library for JavaScript and Node.js
math.ceil(3.2) // returns number 4 math.ceil(3.8) // returns number 4 math.ceil(-4.2) // returns number -4 math.ceil(-4.7) // returns number -4 math.ceil(3.212, 2) // returns number 3.22 math.ceil(3.288, 2) // returns number 3.29 math.ceil(-4.212, 2) // returns number -4.21 math.ceil(-4.782, ...
🌐
GitHub
gist.github.com › z2015 › 5e20455d01ece6d3a1a6d9f09156fba6
ceil vs floor vs round · GitHub
The Math.ceil() function returns the smallest integer greater than or equal to a given number.
Top answer
1 of 1
2

The construct:

Math.ceil(averageCost / 10) * 10;

Does a form of rounding. It has the net effect of rounding up to the nearest whole number multiple of 10. So:

11 => 20
20 => 20
21 => 30
11.99 => 20

Math.ceil(averageCost / 10) divides by 10 and rounds up to the nearest whole number (removing all decimal portions and all ones) and then the * 10 brings it back to the same numeric range it was originally in, but without the parts removed by the rounding.

Here's an example showing a number of results:

const nums = [10,11,15,18,19,20,21,10.1,11.99,20.19];

for (let num of nums) {
     let result = Math.ceil(num/10) * 10;
     console.log("Input: ", num, ", Output: ", result);
}


Why wouldn't we just use Math.ceil? Doesn't it effectively do the same thing as the above? Is there a condition where Math.ceil doesn't work?

This combination rounds up to the nearest whole number multiple of 10 whereas Math.ceil() only rounds up to the nearest whole number. So, the two cases you ask about have different uses. Use the one that accomplishes what you want to accomplish. For a number where the integer portion is already a power of ten such as 10.3, the two would have the same output, but for any other number such as 11.3, the two would not have the same output.

Math.ceil(11.3) === 11
(Math.ceil(11.3 / 10) * 10) === 20

Is there a condition where the Math.ceil() function in Javascript doesn't remove decimals from the output?

No. There is not. It's whole function is to round up to the nearest whole number (thus removing any decimal fraction from the number).

So I'm at a loss for why I'd see a division by 10 with a subsequent multiplication of 10.

To round up to the nearest whole number multiple of 10.

Find elsewhere
🌐
Educative
educative.io › answers › mathceil-mathfloor-and-mathround-in-javascript
Math.ceil, Math.floor, and Math.round in JavaScript
The Math.ceil function in JavaScript is used to round up a number that is passed into it to its nearest integer. What do I mean by rounding up? I mean towards the greater value. Math.ceil() only takes one parameter, the value to be rounded.
🌐
LaunchCode
education.launchcode.org › intro-to-professional-web-dev › appendices › math-method-examples › ceilfloortrunc-examples.html
Math.ceil, floor, and trunc Examples — Introduction to Professional Web Development in JavaScript documentation
At first glance, Math.floor and Math.trunc appear to do exactly the same thing. However, a closer look shows that the two methods treat negative numbers differently. ... When combined with the map array method, ceil, floor, and trunc will operate on each entry in an array.
🌐
Codecademy
codecademy.com › forum_questions › 4f35e646fe0083000301a5e5
1.2: Why not use Math.ceil? | Codecademy
console.log(Math.floor(52.59)); console.log(Math.ceil(52.59)); Refer to the Mozilla docs for more info: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/ceil https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/floor
🌐
Hugo
gohugo.io › functions › math › ceil
math.Ceil
March 5, 2025 - GitHub 86668 stars Mastodon · Hugo Documentation · Returns the least integer value greater than or equal to the given number. Syntax · math.Ceil VALUE · Returns · float64 · {{ math.Ceil 2.1 }} → 3 · Last updated: March 5, 2025 : content: ...
🌐
TutorialsPoint
tutorialspoint.com › javascript › math_ceil.htm
JavaScript Math.ceil() Method
The JavaScript Math.ceil() method accepts a numeric value as a parameter and rounds it UP to the smallest integer greater than or equal to that number. For instance, if we pass a numeric value "7.20" to this method, it rounds it to "8" because it is
🌐
Reintech
reintech.io › blog › implementing-math-ceil-method-javascript
Implementing the Math.ceil() Method | Reintech media
January 1, 2026 - In this tutorial, we will learn how to implement the Math.ceil() method in JavaScript. We will look at its syntax, example usage, and use cases for it.
🌐
Accolades Dev
blog.accolades.dev › home › web-development and seo › math.ceil()in javascript
Math.ceil()in Javascript
April 4, 2023 - Math.ceil() rounds up decimal numbers to the nearest integer in JavacsriptS, useful for precise number manipulation.
🌐
GoLinuxCloud
golinuxcloud.com › home › javascript › how to use math.ceil in javascript? [solved]
How to use math.ceil in JavaScript? [SOLVED] | GoLinuxCloud
November 11, 2022 - number1 = 4.01; number2 = 3.98; ... the number is from the higher (or next) absolute value, it will round up to it via the ceil() method....
🌐
Scaler
scaler.com › home › topics › math ceil() javascript
Math ceil() JavaScript- Scaler Topics
June 22, 2022 - The ceil() is a JavaScript function that returns the lowest integer value that is greater than or equal to a given number. In other words, the ceil() method produces an integer value after rounding up a number.