Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Created April 5, 2019 12:09
Show Gist options
  • Save karl-gustav/66ebe8cf3ce81e7b66c187b08caf1d25 to your computer and use it in GitHub Desktop.
Save karl-gustav/66ebe8cf3ce81e7b66c187b08caf1d25 to your computer and use it in GitHub Desktop.
helper math functions in javascript
// fixes that 2.55 is rounded to 2.5 and not 2.6 as it should have been
export function round(num, digits) {
digits = isNaN(digits) ? 2 : digits;
return +(Math.round(num + "e+" + digits) + "e-" + digits).toFixed(digits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment