SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Math Functions

parseFloat function for string to Float

By using parseFloat function we can convert strings to float numbers. To convert string to integer we can use parseInt function. Using this function we can only convert string numbers to numeric data but alphabetic characters we can't convert.

var t1=parseFloat(x);

Main use of the parseFloat function is to convert user entered data of a text box to number as by default all the data entered through a text box is string.

Let us try to learn parseFloat function by using one example. Try to enter two numbers in two text fields. The sum of the two numbers will be displayed on click of a button.

Demo of ParseFloat()

The code is here

<script type="text/javascript">
function disp_data(){
document.getElementById("a2").innerHTML=parseFloat(document.getElementById('t1').value) + parseFloat(document.getElementById('t2').value);

<input type=text name=t1 id='t1' > <input type=text name=t2 id='t2' > <input type=button value='Display Sum' onClick='disp_data()';>
<div id='a2' style=" background-color: #c0f0c0; width:200" > Enter a number</div>

<p class='demo'><a href=math-parseFloat.php>Back to Tutorial of Math.parseFloat() function</a></p>


Post Comment This is for short comments only. Use the forum for more discussions.
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer