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

6 Answers

0 votes
var s = "17.39 points set to 10.33";

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

17.39
 
*/

 



answered Jun 12, 2015 by avibootz
0 votes
var s = "17.99 points";

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

17.99
 
*/

 



answered Jun 12, 2015 by avibootz
0 votes
var s = "200 17.99 points";

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

200 
 
*/

 



answered Jun 12, 2015 by avibootz
0 votes
var s = "17.99 3.14 points";

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

17.99  
 
*/

 



answered Jun 12, 2015 by avibootz
0 votes
var s = "3.14";

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

3.14 
 
*/

 



answered Jun 12, 2015 by avibootz
0 votes
var s = "3000";

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

30000 
 
*/

 



answered Jun 12, 2015 by avibootz
...