You are not logged in.
#1 2012-07-26 03:38:49
How to convert a string into float using JavaScript?
Convert String Into Float Using JavaScript:
Suppose we have a value that contains coma like 200,52600 then how to convert this string value to the float in javascript.
Replace the comma with a dot then it will be able to convert into a float value by using javascript.
var value = parseFloat("200,52600");
This will only return 200:
var value = parseFloat("200,52600");
This will return 200.52600:
So in the end, we can simply use below code.
var fValue = parseFloat(document.getElementById("textfieldid").value.replace(",","."))
Do not forget that parseInt() should only be used to parse integers (no floating points). In this case it will only return 200. Additionally, calling parseInt() on a float will not round the number: it will take its floor (closest lower integer).
Online Web Tutorials And Interview Questions With Answers Forum:
https://www.globalguideline.com/forum/
Offline
2012-07-26 03:38:49
- Advertisement
- Ads By Google
Re: How to convert a string into float using JavaScript?
#2 2012-10-16 13:04:01
- maire.oldfield
- Member
- Registered: 2012-10-16
- Posts: 5
Re: How to convert a string into float using JavaScript?
This is vary nice information in java Script .... these information is vary useful for me and other java script user ................ thanks for sharing this nice information.......
Offline