Home Javascript JavaScript floor method
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

JavaScript floor method

Advertisement
JavaScript floor method is used to achieve the next complete number in the downward position.

JavaScript floor method

     

JavaScript floor method is used to achieve the next complete number in the downward position. For example if we apply the floor method on the number like "1.2213" then it will return the floor value as "1" and if we will provide some negative number as "-4.463465" then it will return the number as "-5".

Syntax:

   Math.floor( number) ;

Description of code: 

We have created an input text box in which user can provide the number of which we have to calculate the floor value. When user clicks on the button "Show Floor value" it calls the method callFloor() . In the callFloor() method it takes the number from the text box and shows the floor value in the alert message by using the alert() method. Here is the full example code of floorExample.html as follows:

<html>
<body>
<script>
function callFloor(){
var val= document.getElementById("txt").value;
alert(Math.floor(val));
}
</script>
<div style="background: #cf2255; width:'100%';" align="center">
<font color="#ffffcc" size="12pt">
<b>Floor Example</b>
</font>
</div>
<center>
<div style="background: #ffffcc; width:'100%';" align="center">
Input any decimal number(9999.9999) :<input type="text" id="txt" value=""/>
<button onclick="callFloor();">Show Floor Value</button>
</div>
</center>
</body>
</html>

Output :

Input any number to find its floor value.

Download Source Code

     

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 29, 2009

Ask Questions?    Discuss: JavaScript floor method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com