Skip to content

Commit

Permalink
fix: handled 0 denominator input
Browse files Browse the repository at this point in the history
  • Loading branch information
kom-senapati committed Feb 11, 2024
1 parent 9f16847 commit 9443a11
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Calculators/Percentage-Fraction-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ window.convertFractionToPercent = function () {
var numerator = parseInt(parts[0]);
var denominator = parseInt(parts[1]);

// Check if denominator is zero
if (denominator === 0) {
alert('Denominator cannot be zero. Please enter a valid fraction.');
return;
}

// Calculate percentage
var percent = (numerator / denominator) * 100;

Expand Down

0 comments on commit 9443a11

Please sign in to comment.