Last active
July 24, 2020 09:28
-
-
Save porqz/a18a8992cd15bc315457f9fa21ece6c2 to your computer and use it in GitHub Desktop.
Floating point numbers sum workaround
This file contains 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 default function sum(...numbers: number[]): number { | |
return numbers.reduce((sum: number, currentNumber: number) => ( | |
(Math.round(sum * 100) + Math.round(currentNumber * 100)) / 100 | |
), 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment