Created
October 19, 2020 12:23
-
-
Save doasync/838a4f794bb99fb3a2d2ad47a14ffb8e to your computer and use it in GitHub Desktop.
Round number with precision (TypeScrypt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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