Home » JavaScript Tutorial

Math.floor() Method with Example in JavaScript

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

JavaScript | Math.floor() Method

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

Syntax:

    Math.floor(val);

Parameter(s):

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

Return value:

The return type of this method is number, it returns the a number which is rounded down 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.floor(5.21));
console.log(Math.floor(10.98));
console.log(Math.floor(-3.32));
console.log(Math.floor(0));
console.log(Math.floor("7.18"));

Output

5
10
-4
0
7

Example 2: Invalid values for the method.

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

console.log(Math.floor(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.