I have code that converts pixels into inches. But the result is a decimal.
How can I have the result return a fraction for the inch, example: 1/4 instead of .25
Here is the HTML:
<label>Pixels</label>
<input class="calcd" id="calc3" type="text" />
<input class="calcd" id="calc4" type="hidden" value="96" />
<br />Inches <span id="result2"></span>
Here is the Jquery:
$(document).ready(function(){
$(".calcd").keyup(function(){
var val1 = parseInt($("#calc3").val());
var val2 = parseInt($("#calc4").val());
if ( ! isNaN(val1) && ! isNaN(val2))
{
$("#result2").text((val1 / val2).toFixed(2));
}
});
});
I see this here on stackoverflow:
where using the var decimal = eval(fraction);
will work, but am confused on it.
Here is the JsFiddle
2 options you got:
Also you only need one
$(document).ready(function () {
hope this helps.
:)
COde
working screenshot