Below is the example of the Math floor() Method.
- Example:
<script type="text/javascript">document.write("Result : "+ Math.floor(.89));</script>chevron_rightfilter_none - Output:
Result : 0
The Math.floor method is used to round off the number passed as a parameter to its nearest integer in Downward direction of rounding i.e. towards the lesser value.
Syntax:
Math.floor(value)
Parameters: This method accepts single parameter asmentioned above and described below:
- Value: It is the value which is to be tested for Math.floor.
Return Value: The Math.floor() method returns the smallest integer greater than or equal to the given number.
Below examples illustrate the Mathe floor() method in JavaScript:
Input : Math.floor(.89) Output: 0
Input : Math.floor(-89.02) Output : -90
Input : Math.floor(0) Output : 0
More codes for the above method are as follows:
Program 1: When a negative number is passed as a parameter.
<script type="text/javascript"> document.write("Result : " + Math.floor(-89.02)); </script> |
Output:
Result : -90
Program 2: When zero is passed as a parameter.
<script type="text/javascript"> document.write("Result : " + Math.floor(0)); </script> |
Output:
Result : 0
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- PHP Math Functions (abs, pi, deg2rad, rad2deg, fmod, floor, ceil, round, is_finite, is_infinite)
- Lodash _.floor() Method
- Sum of product of x and y such that floor(n/x) = y
- Minimum number of square tiles required to fill the rectangular floor
- p5.js | floor() function
- Summation of floor of harmonic progression
- Floor square root without using sqrt() function : Recursive
- All possible values of floor(N/K) for all values of K
- Floor value Kth root of a number using Recursive Binary Search
- Maximum number of tiles required to cover the floor of given size using 2x1 size tiles
- JavaScript Math cosh() Method
- JavaScript Math random() Method
- JavaScript Math round( ) Method
- JavaScript Math abs( ) Method
- JavaScript Math sqrt( ) Method
- JavaScript Math pow( ) Method
- JavaScript Math trunc( ) Method
- JavaScript Math exp( ) Method
- JavaScript Math log( ) Method
- JavaScript Math cos( ) Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


