Skip to content

Instantly share code, notes, and snippets.

@rowanoulton
Last active December 23, 2015 20:59
Show Gist options
  • Save rowanoulton/6692983 to your computer and use it in GitHub Desktop.
Save rowanoulton/6692983 to your computer and use it in GitHub Desktop.
var val = 1.995,
dp = 2,
scale = Math.pow(10, dp),
rounded = Math.round(val * scale) / scale;
console.log(val + ' ==> ' + rounded); // "1.995 ==> 2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment