Skip to content

Commit

Permalink
refine CalculatePercentage
Browse files Browse the repository at this point in the history
  • Loading branch information
canonbrother committed Oct 10, 2024
1 parent 4056d3d commit 1bf704a
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/utils/index/CalculatePercentage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ export function CalculatePercentage(
value1: number | undefined,
value2: number | undefined,
): string {
if (value1 === undefined || value2 === undefined) {
return "";
}
if (value2 === 0) {
const result = value1 / value2;

Check failure on line 5 in src/utils/index/CalculatePercentage.ts

View workflow job for this annotation

GitHub Actions / Lint - Typescript and ESLint

'value1' is possibly 'undefined'.

Check failure on line 5 in src/utils/index/CalculatePercentage.ts

View workflow job for this annotation

GitHub Actions / Lint - Typescript and ESLint

'value2' is possibly 'undefined'.
if (isNaN(result)) {
return "0.00%";
}

return `${((value1 / value2) * 100).toFixed(2)}%`;
return `${(result * 100).toFixed(2)}%`;
}

0 comments on commit 1bf704a

Please sign in to comment.