Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert string to number in jquery
How to convert string to number in jquery

First of all, JS does not require jquery to convert a Chinese string into a number.

For a string that conforms to the number format, the simplest method is as follows: var?numStr?=?' 99.9';//?Or integer?'999'

//?As long as you add the "+" symbol in front of the string, you can convert the string type into the number type

var?num?=?+numStr;

For some strings with illegal strings appended at the end, you need to use parseInt or parseFloat//?For integer:

var? integer?=?'99%';

var?result?=?parseInt(integer);

//?For floating point type

var? decimal?=?'99.9%';

var?result?=?parseFloat(decimal);

For numeric strings in other bases //? as binary

var?binary?=?'1001';

var?result?=?parseInt(binary,?2);

//?as octal

var?octonary?=?'077';

var?result?=?parseInt(octonary,?8);

//? as hexadecimal

var?hex?=?'0xff';

var?result?=?parseInt(hex,?16);