String to Float Conversion in JavaScript

JavaScriptFloats are decimal numbers.  Similar to previous tutorial, if a float number is inside a quotation marks, it is treated as string by JavaScript.  To convert a string to float, we make use of parseFloat() function.  Example is given below.

<title>JavaScript Tutorial </title>
<script type="text/javascript">
var f1 = "1.35";
var f2 = "2.55";
var total = f1+f2;
var sum = parseFloat(f1) + parseFloat(f2);
//Total = 1.352.55
//Sum = 3.9