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