jQuery – Convert string to float or double

Find code to convert String to float or double using jQuery. To convert, use JavaScript parseFloat() function parses a string and returns a floating point number.

var sVal = '234.54';
var iNum = parseFloat(sVal); //Output will be 234.54.

Related Post:

The syntax of parseFloat() function is,

parseFloat(string)

If you string contains spaces then only first number will be returned.

var sVal = '23.25 45.25 68';
var iNum = parseFloat(sVal); //Output will be 23.25

This function will only return "NaN", if the first character cannot be converted to a number.

Feel free to contact me for any help related to jQuery, I will gladly help you.



Responsive Menu
Add more content here...