calculator - I want to use the math.round function in a jquery file but I do not know where to place it to arrive at the wanted result -
i trying make calculator in jquery, , managed couple of things encounted issues , need help. want place math. round function code make division result more pleasant-looking not know where. tried .tofixed not example if have operation 5/2, result 2,500 , want 2.5. adressing wrong var? lost. here code:
$operators.click(function (event) { event.preventdefault(); var currvalue = $(this).text(); var curroperand = parsefloat($display.text()); if (currvalue != 'ce') { if (operation != null && !afteroperation) { switch (operation) { case '+': $display.text(operand + curroperand); break; case '-': $display.text(operand - curroperand); break; case '*': $display.text(operand * curroperand); break; case '/': if (curroperand != 0) { $display.text((operand / curroperand).tofixed(3)); } else { alert("error"); reset(); } break;
highly appreciate help
add number
in division
case:
$display.text(number((operand / curroperand).tofixed(3)));
this first convert string number
.
another way
you can use parsefloat
:
parsefloat((5 / 2).tofixed(3))
Comments
Post a Comment