Skip to content

Instantly share code, notes, and snippets.

@darkredz
Created September 6, 2013 08:24
Show Gist options
  • Select an option

  • Save darkredz/6461003 to your computer and use it in GitHub Desktop.

Select an option

Save darkredz/6461003 to your computer and use it in GitHub Desktop.
Str to Int
var s = '19820';
s = s.split('');
var intVar = 0;
var factor = (s.length==1) ? 1 : Math.pow(10, s.length-1) ;
for(var i=0; i< s.length; i++){
intVar += s[i] * factor;
factor = factor/10;
}
console.log(intVar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment