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 9b51e75
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utils/index/CalculatePercentage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export function CalculatePercentage(
if (value1 === undefined || value2 === undefined) {
return "";
}
if (value2 === 0) {

const result = value1 / value2;
if (isNaN(result)) {
return "0.00%";
}

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

0 comments on commit 9b51e75

Please sign in to comment.