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 stringVal = '334.546';
var intNum = parseFloat(stringVal ); //Output will be 334.546.
The syntax of parseFloat() function is,
parseFloat(string)
If you string contains spaces then only first number will be returned.
var stringVal = '233.25 453.25 683';
var intNum = parseFloat(stringVal); //Output will be 233.25
This function will only return "NaN", if the first character cannot be converted to a number.
Javascript
jQuery
- asked 6 years ago
- G John