Math Floor Javascript Method

By Saheb Sutradhar - Updated On 27-02-2024

Math Floor Javascript Method

 

In this post, we are going to learn what is Math.floor() in javascript, how we can use it and when we need to use this in real-time applications.

Javascript Math.floor(value) method takes a number type value as a parameter and returns the round off of that value. The return value will be the nearest downward integer.

Example:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
		document.write("Output   : " + Math.floor(.60));
</script>
</body>
</html>

Output:

Output   : 0

Syntax:

Math.floor(value);

Example 1 :

Math.floor(.90);
Output : 0

Example 2 :

Math.floor(-99.91);
Output : -100

Example 3 :

Math.floor(20);
Output : 20

In real-time application, if you have any requirement where the input id is 11.23 and you need to display 11 there you can use javascript Math.floor() method.

This method is supported by most browsers like Chrome, IE, Safari, Firefox etc.

 

codelearningpoint © 2024