Skip to content

Instantly share code, notes, and snippets.

@JordanDelcros
Created June 4, 2021 13:49
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 JordanDelcros/86f454c5e832c5c4e6d4b00ff739a8fb to your computer and use it in GitHub Desktop.
Save JordanDelcros/86f454c5e832c5c4e6d4b00ff739a8fb to your computer and use it in GitHub Desktop.
Fixed number without .toFixed()
// Default 2 numbers after comma
function fixNumber( number, precision = 1e2 ){
return Math.sign(number) * (Math.round((Math.abs(number) + Number.EPSILON) * precision) / precision);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment