How to Set a JavaScript VAR to Float
- 1). Launch the standard, plain-text text editor application that is available on your computer.
- 2). Enter the following code into the text editor.
<html>
<body>
<script type="text/javascript">
var numberstring="123.456";
var floatingnumber;
document.write("This is the string, 123.456 converted to a floating point number: " + parseFloat(numberstring)+"");
floatingnumber=parseFloat(numberstring)+.01;
document.write("Add the 0.1 to this and get: "+floatingnumber+"");
document.write("Add the 0.1 to the string, 123.456 and get: "+numberstring+.01+"");
</script>
</body>
</html> - 3). Click the File menu. Select the "Save" option. Save under the file name "test.html".
- 4). Launch the web browser that is available on your computer. Click on the "File" menu item and select "Open File"
- 5). Locate the file "test.html" just created, select it with the mouse then click on "Open".
Source...