×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

Math.ceil() Method with Example in JavaScript

JavaScript | Math.ceil() Method: Here, we are going to learn about the ceil() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on December 23, 2019

JavaScript | Math.ceil() Method

Math.ceil() is a function in math library of JavaScript that is used to round up the number passed to the function. The method will return the nearest integer value indeed is greater than the passed number.

Syntax

    Math.ceil(val);

Parameters

  • val – It represents the value to be rounded up.

Return Value

The return type of this method is number, it returns the a number which is rounded up value of the number passed to the method.

Technical Insights

  • JavaScript version: ECMAScript 1
  • Browser support: Chrome, Internet Explorer, Mozilla, Safari, Opera mini

Values accepted

Integer, floating point, single value array, numeric string.

Invalid Values

Non-numeric string, multi value array, empty variable, empty array all will return NaN (not a number).

Example 1: Valid values for the method

console.log(Math.ceil(5.21));
console.log(Math.ceil(10.98));
console.log(Math.ceil(-3.32));
console.log(Math.ceil(0));
console.log(Math.ceil("7.18"));

Output

6
11
-3
0
8

Example 2: Invalid values for the method

console.log(Math.ceil("IncludeHelp"));
// Output: NaN

console.log(Math.ceil(1 + 5i));
// Output: Uncaught SyntaxError: Invalid or unexpected token

JavaScript Math Object Methods »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.