How to return the int part from decimal number from the start of a string in JavaScript

6 Answers

0 votes
var s = "100 points";

document.write(parseInt(s));
 
/*
run:

100
 
*/

 



answered Jun 11, 2015 by avibootz
edited Jun 12, 2015 by avibootz
0 votes
var s = "100 90 points";

document.write(parseInt(s));
 
/*
run:

100
 
*/

 



answered Jun 11, 2015 by avibootz
edited Jun 12, 2015 by avibootz
0 votes
var s = "100.83 percent";

document.write(parseInt(s));
 
/*
run:

100
 
*/

 



answered Jun 11, 2015 by avibootz
edited Jun 12, 2015 by avibootz
0 votes
var s = "100";

document.write(parseInt(s));
 
/*
run:

100
 
*/

 



answered Jun 11, 2015 by avibootz
edited Jun 12, 2015 by avibootz
0 votes
var s = "points set to 100";

document.write(parseInt(s));
 
/*
run:

NaN 
 
*/

 



answered Jun 11, 2015 by avibootz
edited Jun 12, 2015 by avibootz
0 votes
var s = "17.39 points set to 10.33";

document.write(parseInt(s));
 
/*
run:

17
 
*/

 



answered Jun 12, 2015 by avibootz
...