Created
February 19, 2013 21:05
-
-
Save ryasmi/4989919 to your computer and use it in GitHub Desktop.
Rounds an floating point number to an integer.
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
var round = function (value) { | |
// {value is some number} | |
var multiplier = Math.abs(value) / value; | |
var sValue = (value + (0.5 * multiplier)).toString(); | |
var point = sValue.indexOf("."); | |
return parseInt(sValue.substring(0, point === -1 ? sValue.length : point), 10); | |
// {returns value rounded} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment