JavaScript does string to int using the Number method

  • 2020-03-30 02:58:13
  • OfStack

var str='1250' ; 

alert( Number(str) ); //You get 1250

alert(parseInt(str)); //You get 1250

var str1='00100'; 

alert( Number(str1) ); //You get 100

alert(parseInt(str1)); //You get 64

It is found that the parseInt method converts a Number beginning with format'00' as a 2-to-10 method, so it is recommended that string to int is best used with the Number method

Related articles: