fix: refactor number utils (#7504)

pull/7507/head
Andrey Blazejuk 1 month ago committed by GitHub
parent 5033c89adf
commit 55255dbbb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      src/helper/number.ts

@ -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);
} }

Loading…
Cancel
Save