Fractional number
-
Hi Is there a problem converting a decimal number to a fraction?
For example, the user typed the decimal number 0.75 and the result will be 3/4.
I couldn’t solve this equation. I tried a few alternatives but they didn’t work.fieldname40: Value entered by user
the equation should be like this
0.75 = 75/100
gcd(75,100) = 25
0.75 = (75/25)/(100/25) = 3/4Empty State of Code
(function() { var kriter2 = fieldname40; CODE jQuery('#calculation-kriter2').html(kriter2); jQuery('.kriter2-aciklama').html('Sonuç : '); jQuery('.kriter2-sonuc').html(kriter2); return [kriter2]; })();The method I tried the code
(function() { var ondalikSayi = parseFloat(document.getElementById('fieldname40').value); var payda = 1; while (ondalikSayi % 1 !== 0) { ondalikSayi *= 10; payda *= 10; } var pay = Math.round(ondalikSayi); var kriter2 = pay + "/" + payda; jQuery('#calculation-kriter2').html(kriter2); jQuery('.kriter2-aciklama').html('Sonuç : ' + kriter2); jQuery('.kriter2-sonuc').html(kriter2); return [kriter2]; })();
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘Fractional number’ is closed to new replies.
