Free HTML code for Fraction to percent convertor online
We will try to give you a new code for every day .
Here is a code for fraction to percent 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>Fraction to Percent Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h2>Fraction to Percent Converter</h2>
<label for="fractionInput">Enter Fraction (e.g., 1/2):</label>
<input id="fractionInput" placeholder="Enter fraction" type="text" />
<button onclick="convertFractionToPercent()">Convert</button>
<p id="result"></p>
<script>
function convertFractionToPercent() {
// Get the fraction input value
var fractionInput = document.getElementById("fractionInput").value;
// Split the fraction into numerator and denominator
var parts = fractionInput.split('/');
var numerator = parseInt(parts[0]);
var denominator = parseInt(parts[1]);
// Check if the input is a valid fraction
if (isNaN(numerator) || isNaN(denominator) || denominator === 0) {
document.getElementById("result").innerHTML = "Invalid fraction input";
return;
}
// Convert fraction to percent
var percent = (numerator / denominator) * 100;
// Display the result
document.getElementById("result").innerHTML = "Percent: " + percent + "%";
}
</script>
</body>
</html>
Comments
Post a Comment