1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-01-16 21:58:30 +01:00

fix: refactor number utils (#7504)

This commit is contained in:
Andrey Blazejuk 2024-10-17 04:48:19 -03:00 committed by GitHub
parent 5033c89adf
commit 55255dbbb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,9 +1,12 @@
export function getPercentage(portion: number, total: number): string {
if (total <= 0 || portion <= 0) {
return '0';
} else if (portion > total) {
return '100';
if (portion <= 0 || total <= 0) {
return '0.00';
}
if (portion >= total) {
return '100.00';
}
return ((portion / total) * 100).toFixed(2);
const percentage = (portion / total) * 100;
return percentage.toFixed(2);
}