Created
November 26, 2013 02:01
-
-
Save leemark/7652371 to your computer and use it in GitHub Desktop.
JavaScript convert string to number: parseInt vs. parseFloat vs. unary operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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