Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow up to max 2 decimals for percentages to avoid loss of precision
- Loading branch information
Showing
6 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Round a percentage to max 2 decimals. | ||
* If amount > 100, returns 100 | ||
* If amount < 0, returns 0 | ||
*/ | ||
export const roundPercentage = (amount: number) => { | ||
if (amount > 100) { | ||
return 100; | ||
} | ||
|
||
if (amount < 0) { | ||
return 0; | ||
} | ||
|
||
amount = Math.round(Number(amount) * 100) / 100; | ||
|
||
return amount; | ||
}; |
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
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
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