About
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.
Popular Classes
Scratch Coding
Minecraft Coding
TinkerCAD
Roblox Studio
Python for Kids
Javascript for Kids
Pre-Algebra
Geometry for Kids
Copyright @ Kodeclik 2025. All rights reserved.
Javascript’s Math.floor() method takes a number as input and returns the largest integer less than or equal to the input number. Let us learn how it works by writing a simple Javascript program.
We will embed our Javascript code inside a HTML page like so:
In the above HTML page you see the basic elements of the page like the head element containing the title (“JavaScript’s Math floor() Method”) and a body with an empty script tag. The Javascript code goes inside these tags.
Here is some simple code to experiment with the Math.floor() method:
The output is:
As you can see 3.14 is truncated to 3.
Here are more examples:
The output is:
Math.floor() applied to zero yields zero:
The output is:
Let us apply Math.floor() method to a negative number:
The output is:
Note that Math.floor() applied to -57.68 does not yield -57 (because that is greater than -57.68). The floor yields -58 because that is the largest integer smaller than -57.68 (picture the number line).
If you liked the Math.floor() method, explore the Math.max() method in Javascript and the valueOf() method! Also learn how you can build upon Math.floor() to round down to different levels in Javascript!
Would you like to learn more Javascript? Checkout our blog post on how you can use Javascript Math.max() to find the max element of an array.
Want to learn Javascript with us? Sign up for 1:1 or small group classes.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JavaScript’s Math floor() Method</title>
</head>
<body>
<script>
</script>
</body>
</html>
<script>
pi = 3.14
document.write(pi)
document.write('<BR>')
document.write(Math.floor(pi))
</script>
3.14
3
<script>
document.write("3.14 -> Math.floor() -> " + Math.floor(3.14))
document.write('<BR>')
document.write("3.99 -> Math.floor() -> " + Math.floor(3.99))
document.write('<BR>')
document.write("0.56 -> Math.floor() -> " + Math.floor(0.56))
</script>
3.14 -> Math.floor() -> 3
3.99 -> Math.floor() -> 3
0.56 -> Math.floor() -> 0
<script>
document.write("0.00 -> Math.floor() -> " + Math.floor(0.00))
document.write('<BR>')
</script>
0.00 -> Math.floor() -> 0
<script>
document.write("-57.68 -> Math.floor() -> " + Math.floor(-57.68))
document.write('<BR>')
</script>
-57.68 -> Math.floor() -> -58