diff --git a/Calculators/CGPA-Percentage-Calculator/README.md b/Calculators/CGPA-Percentage-Calculator/README.md new file mode 100644 index 000000000..6c9bbb47e --- /dev/null +++ b/Calculators/CGPA-Percentage-Calculator/README.md @@ -0,0 +1,15 @@ +#

CGPA ⟷ Percentage Calculator

+ +## Description :- + +Quickly convert your CGPA to percentage and vice versa with the CGPA ⟷ Percentage Calculator. On the basis of formula `Percentage = CGPA * 7.1 + 11` and `CGPA = (Percentage - 11) / 7.1` this calculator will help you to convert your CGPA to percentage and vice versa. + +Start typing in any field and the value will be calculated automatically. + +## Tech Stacks :- +- HTML +- CSS +- JavaScript + +## Screenshot :- +![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/e33cfdae-2c31-4ff0-9964-82dffa5495e3) diff --git a/Calculators/CGPA-Percentage-Calculator/index.html b/Calculators/CGPA-Percentage-Calculator/index.html new file mode 100644 index 000000000..8ba5c4cee --- /dev/null +++ b/Calculators/CGPA-Percentage-Calculator/index.html @@ -0,0 +1,51 @@ + + + + CGPA ⟷ Percentage | Calcdiverse + + + + + + +
+
+
+

+ CGPA ⟷ Percentage +

+

+ Start Typing In Any Field +

+
+
+ +
+
+ +
+
+
+
+ + diff --git a/Calculators/CGPA-Percentage-Calculator/script.js b/Calculators/CGPA-Percentage-Calculator/script.js new file mode 100644 index 000000000..e6d429200 --- /dev/null +++ b/Calculators/CGPA-Percentage-Calculator/script.js @@ -0,0 +1,65 @@ +// functions to convert values +function cgpaToPercentage(cgpa) { + return cgpa * 7.1 + 11 +} + +function percentageToCGPA(percentage) { + return (percentage - 11) / 7.1 +} + +// Function to handle conversion and display values +function convertCGPAToPercentage() { + cleanError() + let cgpaInput = parseFloat(document.getElementById('cgpaInput').value) + if (!isNaN(cgpaInput) && cgpaInput >= 0 && cgpaInput <= 10) { + let percentage = cgpaToPercentage(cgpaInput).toFixed(2) + percentageInput.value = percentage + } else { + // resetting values + cgpaInput.value = null + percentageInput.value = null + showError('Invalid CGPA. Please enter a value between 0 and 10.') + } +} + +function convertPercentageToCGPA() { + cleanError() + let percentageInput = parseFloat( + document.getElementById('percentageInput').value + ) + if ( + !isNaN(percentageInput) && + percentageInput >= 0 && + percentageInput <= 100 + ) { + let cgpa = percentageToCGPA(percentageInput).toFixed(2) + // for too low percentage cgpa goes negative + if (cgpa < 0) { + showError('Percentage too low') + } else { + cgpaInput.value = cgpa + } + } else { + // resetting values + cgpaInput.value = null + percentageInput.value = null + showError('Invalid Percentage. Please enter a value between 0 and 100.') + } +} + +document.addEventListener('DOMContentLoaded', function () { + let cgpaInput = document.getElementById('cgpaInput') + let percentageInput = document.getElementById('percentageInput') + cgpaInput.addEventListener('input', convertCGPAToPercentage) + percentageInput.addEventListener('input', convertPercentageToCGPA) +}) + +function showError(message) { + let error = document.getElementById('error') + error.innerHTML = message +} + +function cleanError() { + let error = document.getElementById('error') + error.innerHTML = '' +} diff --git a/Calculators/CGPA-Percentage-Calculator/style.css b/Calculators/CGPA-Percentage-Calculator/style.css new file mode 100644 index 000000000..2d17d319e --- /dev/null +++ b/Calculators/CGPA-Percentage-Calculator/style.css @@ -0,0 +1,5 @@ +input[type='number']::-webkit-inner-spin-button, +input[type='number']::-webkit-outer-spin-button { + -webkit-appearance: none; + margin: 0; +} diff --git a/index.html b/index.html index 834596634..05f97d457 100644 --- a/index.html +++ b/index.html @@ -1709,6 +1709,20 @@

Perfoms mathematical operations on complex numbers.

+
+
+

CGPA Percentage Calculator

+

Converts CGPA to percentage and vice-versa.

+ +
+