Skip to content

Instantly share code, notes, and snippets.

@leemark
Created November 26, 2013 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leemark/7652371 to your computer and use it in GitHub Desktop.
Save leemark/7652371 to your computer and use it in GitHub Desktop.
JavaScript convert string to number: parseInt vs. parseFloat vs. unary operator
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="JavaScript convert string to number: parseInt vs. parseFloat vs. unary op" /><meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var one = parseInt("0123.01ab", 10);
console.log("one: " + one);
var two = parseFloat("0123.01ab");
console.log("two: " + two);
var three = + "0123.01ab";
console.log("three: " + three);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment