Skip to content

Instantly share code, notes, and snippets.

@ryasmi
Created February 19, 2013 21:05
Show Gist options
  • Save ryasmi/4989919 to your computer and use it in GitHub Desktop.
Save ryasmi/4989919 to your computer and use it in GitHub Desktop.
Rounds an floating point number to an integer.
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