Skip to content

Instantly share code, notes, and snippets.

@porqz
Last active July 24, 2020 09:28
Show Gist options
  • Save porqz/a18a8992cd15bc315457f9fa21ece6c2 to your computer and use it in GitHub Desktop.
Save porqz/a18a8992cd15bc315457f9fa21ece6c2 to your computer and use it in GitHub Desktop.
Floating point numbers sum workaround
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