Home Javascript JavaScript floor method



JavaScript floor method
Posted on: January 29, 2009 at 12:00 AM
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

     

Related Tags for JavaScript floor method:
javajavascriptccomidescriptiomethodsedipvivaluenumberreturnidpositionooappwarlikeifforieexampletoexamposexteilitliusecompleteapplyinnegativeasmnextososiosiosletjfloormeproppdodownxaxampsurnsoatplykisllivmplandarxtvascrssririprdthavchi6atiapalugagatpleplprndonomo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript floor method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.