

In my most recent use-case, I wanted particular low fractions like 1/3, 1/9, 2/3 etc. ostensibly represents one third, but fractions.js would (correctly) return 33/100. It depends how low you want to go, though there are certain decimal values that notionally represent fractions, but can't be divided to the 'lowest' fraction that you might want. If the result contains an integer, it will return in the format int d/n so if you want just the fraction, you can split around the space. If the result is an integer, it will return the same integer. As per answer, it calculates the greatest common divisor of a non-integer and returns it as the lowest fraction it can make as a string: var myNum = 0.5 Ĭonsole.log(fraction.toString()) // Returns 1/2 If you're open to using a small third-party script, you could take a look at fraction.js. How would I be able to simplify these fractions? (I am decently new to code) Thanks :) So currently my calculator works but none of the fractions are simplified. Number4 = parseInt(document.getElementById("n4").value)

Number3 = parseInt(document.getElementById("n3").value) Number2 = parseInt(document.getElementById("n2").value)
-o7u6l.gif)
Number1 = parseInt(document.getElementById("n1").value)
FRACTION CONVERTER JAVASCRIPT CODE
So my current code for my multiplication part fo my calculator is this: function multiply() Selection = document.getElementById('operation').value The non script part of my calculator is this (With all the inputs): Īnd my option function is this: function option()
