Skip to content

Instantly share code, notes, and snippets.

@lyatziv
Created April 13, 2022 16:55
Show Gist options
  • Save lyatziv/04fade2918c382b7f4c6745868a09400 to your computer and use it in GitHub Desktop.
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.
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