Skip to content

Instantly share code, notes, and snippets.

@itswindtw
Last active May 7, 2016 06:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itswindtw/46a1b05988ba786f6bce33d635e9745d to your computer and use it in GitHub Desktop.
Save itswindtw/46a1b05988ba786f6bce33d635e9745d to your computer and use it in GitHub Desktop.
weird behavior in Chrome 50 (Windows only)
<html>
<head>
</head>
<body>
<script>
var test = function (str) {
with(Math) { // whatever
var scalar = parseFloat(str);
var unit = str.replace(/-?\d+(\.\d*)?/g, "");
var unitsToPt = {"cm": 28.34646, "pt": 1.0};
// unitsToPt["cm"] = 28.34646;
console.log(unitsToPt);
if (scalar == 0 && unitsToPt[unit])
return 0;
else if (!unitsToPt[unit])
return str;
else
return (scalar * unitsToPt[unit]);
}
}
for (var i = 0; i < 1000; i++) {
test(27 + i + "cm");
test(0.85 + i + "cm");
test(5.0 + i + "cm");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment