FRee html code for percent to fraction convertor calculator online
We will try to give you a new code for every day .
Here is a code for percent to fraction convertor HTML code
<html lang="en">
<head>
<meta charset="UTF-8"></meta>
<meta content="width=device-width, initial-scale=1.0" name="viewport"></meta>
<title>Percent to Fraction Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h2>Percent to Fraction Converter</h2>
<label for="percentInput">Enter Percent (e.g., 50%):</label>
<input id="percentInput" placeholder="Enter percent" type="text" />
<button onclick="convertPercentToFraction()">Convert</button>
<p id="result"></p>
<script>
function convertPercentToFraction() {
// Get the percent input value
var percentInput = document.getElementById("percentInput").value;
// Remove the percent symbol if present
percentInput = percentInput.replace('%', '');
// Convert percent to fraction
var fraction = percentToFraction(parseFloat(percentInput));
// Display the result
document.getElementById("result").innerHTML = "Fraction: " + fraction;
}
function percentToFraction(percent) {
// Convert percent to fraction
var fraction = percent / 100;
var gcd = findGCD(percent, 100);
// Simplify the fraction
var numerator = percent / gcd;
var denominator = 100 / gcd;
// Format the result as a fraction
return numerator + '/' + denominator;
}
function findGCD(a, b) {
// Find the Greatest Common Divisor (GCD) using Euclidean algorithm
return b === 0 ? a : findGCD(b, a % b);
}
</script>
</body>
</html>
Comments
Post a Comment