SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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.

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 below given first two text fields. The sum of the two numbers will be displayed inside third text box. Here is the demo.

Enter fist value
Enter Second value
Sum


Here is the code of this demo

<html>

<head>
<title>(Type a title for your page here)</title>
<script type="text/javascript">
function to_add(){
document.f1.t3.value=parseFloat(document.f1.t1.value) + parseFloat(document.f1.t2.value);
}

</script>

</head>

<body>

<form method=post name=f1 ><br>
Enter fist value<input type=text name=t1 onBlur="to_add();"><br>
Enter Second value<input type=text name=t2 onBlur="to_add();"><br>
Sum <input type=text name=t3>
</form>
</body>

</html>






Join Our Email List
Email:  
For Email Newsletters you can trust
Math functions