-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminating-decimal.html
32 lines (32 loc) · 1.11 KB
/
terminating-decimal.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html>
<html>
<head>
<title>Terminating Decimal to Fraction</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<style>
body {background-color: #222; position: relative; left: 10px; width: 90vw; height: 90vh;}
a, div, h1, p, span, th, td {color: #fff; font-family: verdana;}
#number {font-size: 25px; width: 1000px; display: block; margin: 20px 0px;}
#fraction {font-size: 150%;}
</style>
<script src="https://raw.githack.com/rawify/Fraction.js/master/bigfraction.js"></script>
</head>
<body>
<h1>Terminating Decimal to Fraction</h1>
<span>Type any integer or terminating decimal. Powered by fraction.js.</span>
<input id="number"><div id="fraction"></div><br>
<script>
setInterval(function() {
frac = new Fraction(String(number.value));
num = BigInt(frac.n) % BigInt(frac.d);
den = frac.d;
fancyNum = String(num).replace(/(\d+)/g, "<sup>$1</sup>");
fancyDen = String(den).replace(/(\d+)/g, "<sub>$1</sub>");
frac = frac.toFraction(true);
frac = frac.replace(num + "/", fancyNum + "/");
frac = frac.replace("/" + den, "/" + fancyDen);
fraction.innerHTML = "<b>" + frac + "</b>";
});
</script>
</body>
</html>