Created
October 25, 2010 12:08
-
-
Save BonsaiDen/644843 to your computer and use it in GitHub Desktop.
Math.round faster, like 40% or something
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
function round(data) { | |
if (data < 0) { | |
var l = (data + 1 | 0) - data; | |
return (l >= 1.0 && l <= 1.5) ? data | 0 : data - 1 | 0; | |
} | |
var l = data | 0; | |
return data - l >= 0.5 ? data + 1 | 0 : l; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment