jQuery – Convert string to int float or double

jQuery doesn’t have a built-in function to carry out this task because JavaScript already had them.

Convert string to int

The JavaScript parseInt() function can convert any string with a number to int.

parseInt("10")
=> 10
parseInt("10.1")
=> 10

Convert string to float or double

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

parseFloat("123.23");
=> 123.23
parseFloat("1.2 2.3 3.4");
=> 1.2

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top