Created
January 28, 2018 23:27
-
-
Save proprietary/7a19747f3f3fa397a6885d26c1405c02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 roundTiesToEven(n) { | |
var TOLERANCE = 1e-6 | |
if (Math.abs(n%1 - 0.5) <= TOLERANCE) { | |
var f = Math.floor(n) | |
return f%2 === 0 ? f : f+1 | |
} else { | |
return Math.round(n) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment