mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-17 14:41:52 +02:00
fix: refactor number utils (#7504)
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
export function getPercentage(portion: number, total: number): string {
|
export function getPercentage(portion: number, total: number): string {
|
||||||
if (total <= 0 || portion <= 0) {
|
if (portion <= 0 || total <= 0) {
|
||||||
return '0';
|
return '0.00';
|
||||||
} else if (portion > total) {
|
|
||||||
return '100';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((portion / total) * 100).toFixed(2);
|
if (portion >= total) {
|
||||||
|
return '100.00';
|
||||||
|
}
|
||||||
|
|
||||||
|
const percentage = (portion / total) * 100;
|
||||||
|
return percentage.toFixed(2);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user