Skip to content

Commit

Permalink
feat(math): calcDiscount (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd authored Mar 2, 2023
2 parents 551fc24 + ac7c18b commit 17db335
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/math/src/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,8 @@ export const hex = (bytes: Uint8Array): string => {
}
return str;
};

export const calcDiscount = (price: number, finalPrice: number, decimal = 2, upSide = true): number => {
decimal = Math.pow(10, decimal);
return Math.round((price - finalPrice) / (upSide ? finalPrice : price) * 100 * decimal) / decimal;
};

0 comments on commit 17db335

Please sign in to comment.