| |
|
parseFloat function for string to number |
By using parseFloat function we can convert strings to numbers. 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.
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>
| |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|
| JavaScript Tutorials |
| Math Functions |
|
|
|
| Popular Tutorials |
|
| Drop down list |
| Timer function |
| JavaScript Tutorials |
|
| String |
| Array |
| Date & Time |
| Form Validation |
| Event Handling |
| Math Functions |
| Loops & structure |
| JavaScript Forum |
| Subscribe |
|
Submit your email address and receive
article and product notifications. Your email is safe with us.
|
|
|
|