Home » JavaScript Tutorial

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);

Parameter(s):

  • 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





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.