Created
April 13, 2022 16:55
-
-
Save lyatziv/04fade2918c382b7f4c6745868a09400 to your computer and use it in GitHub Desktop.
javascript math is weird. I wrote this because I got tired of getting a headache whenever trying to add decimals.
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 addFixed = (a: number, b: number, p = 0) => { | |
const t = Number(`1${'0'.repeat(p)}`); | |
return (a * t + b * t) / t; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment