Sunday, November 15, 2009

[jQuery] Round numbers

Hi,

The below calculates a couple of textboxes and then allows for the
user to click an up or down image to re calculate decreasing or
increasing a number. Question is how can I round up the result to no
decimal places?

And ….. . any suggestions on how to improve the code would be good.


$(document).ready(function() {

$("#firstBox, #secondBox, #thirdBox, #forthBox").change(function cal
() {
$("#thirdBox").val( ((Number($("#forthBox").val()) * Number($
("#secondBox").val()) )/100 )- Number($("#firstBox").val()));
});


$("#Increase").click(function() {
$("#forthBox").val(5 + Number($("#forthBox").val()) );
$("#thirdBox").val( ((Number($("#forthBox").val()) * Number($
("#secondBox").val()) )/100 )- Number($("#firstBox").val()));
});

$("#Decrease").click(function() {
$("#forthBox").val( Number($("#forthBox").val()) - 5 );
$("#thirdBox").val( ((Number($("#forthBox").val()) * Number($
("#secondBox").val()) )/100 )- Number($("#firstBox").val()));
});

});

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate