Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cccabdalla/c665bf30ecee5ff8e69eb70b09f6bd52 to your computer and use it in GitHub Desktop.
Save cccabdalla/c665bf30ecee5ff8e69eb70b09f6bd52 to your computer and use it in GitHub Desktop.
console.log(Number(Math.round(1.005 + "e2") + "e-2")) // 1.01
const roundAccurately = (number, decimalPlaces) => Number(Math.round(number + "e" + decimalPlaces) + "e-" + decimalPlaces)
console.log(roundAccurately(1.005, 2)) // 1.01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment