Skip to content

Instantly share code, notes, and snippets.

@doasync
Created October 19, 2020 12:23
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 doasync/838a4f794bb99fb3a2d2ad47a14ffb8e to your computer and use it in GitHub Desktop.
Save doasync/838a4f794bb99fb3a2d2ad47a14ffb8e to your computer and use it in GitHub Desktop.
Round number with precision (TypeScrypt)
export const round = (number: number, fractionDigits = 0): number => {
const digits = 10 ** fractionDigits;
const value = number * digits * (1 + Number.EPSILON);
return Math.round(value) / digits;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment