Free html code for Improper Fraction to mixed number calculator convertor online
We will try to give you a new code for every day .
Here is a code for Improper fraction to Mixed number calculator 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>Improper Fraction to Mixed Number Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
</style>
</head>
<body>
<h2>Improper Fraction to Mixed Number Converter</h2>
<label for="improperFractionInput">Enter Improper Fraction (e.g., 5/2):</label>
<input id="improperFractionInput" placeholder="Enter improper fraction" type="text" />
<button onclick="convertImproperFractionToMixedNumber()">Convert</button>
<p id="result"></p>
<script>
function convertImproperFractionToMixedNumber() {
// Get the improper fraction input value
var improperFractionInput = document.getElementById("improperFractionInput").value;
// Convert improper fraction to mixed number
var mixedNumber = improperFractionToMixedNumber(improperFractionInput);
// Display the result
document.getElementById("result").innerHTML = "Mixed Number: " + mixedNumber;
}
function improperFractionToMixedNumber(improperFraction) {
// Split the improper fraction into numerator and denominator
var fractionParts = improperFraction.split('/');
var numerator = parseInt(fractionParts[0]);
var denominator = parseInt(fractionParts[1]);
// Calculate the whole number and the remaining numerator
var wholeNumber = Math.floor(numerator / denominator);
var remainingNumerator = numerator % denominator;
// Format the result as a mixed number
if (wholeNumber === 0) {
return remainingNumerator + '/' + denominator;
} else if (remainingNumerator === 0) {
return wholeNumber.toString();
} else {
return wholeNumber + ' ' + remainingNumerator + '/' + denominator;
}
}
</script>
</body>
</html>
Comments
Post a Comment