From 55255dbbb12700931a0450c884e78bb928e00e0d Mon Sep 17 00:00:00 2001 From: Andrey Blazejuk Date: Thu, 17 Oct 2024 04:48:19 -0300 Subject: [PATCH] fix: refactor number utils (#7504) --- src/helper/number.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/helper/number.ts b/src/helper/number.ts index fc67f117a..f62d25dd3 100644 --- a/src/helper/number.ts +++ b/src/helper/number.ts @@ -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); }