-4

how to get round figure of sum value

now its showing like this http://www.koolfree.com/ImageUpload/uploads/1380114018.jpg

and i want like that http://www.koolfree.com/ImageUpload/uploads/1380160965.jpg

please help me to fix this issue thanks

<script type="text/javascript"><!--
function updatesum() {
document.form.sum.value = (document.form.sum1.value -0) / (document.form.sum2.value -0);
}
//--></script>

<body>

<form name="form" >
Enter a number:
<input name="sum1" onChange="updatesum()" />
and another number:
<input name="sum2" onChange="updatesum()" />
Their sum is:
<input name="sum" readonly style="border:0px;">
</form>

</body>
user2468472
  • 281
  • 2
  • 8
  • 15
  • does this help you: http://stackoverflow.com/questions/11832914/round-up-to-2-decimal-places-in-javascript – baam Sep 25 '13 at 12:27
  • possible duplicate of http://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places, http://stackoverflow.com/questions/4187146/display-two-decimal-places-no-rounding, http://stackoverflow.com/questions/11832914/round-up-to-2-decimal-places-in-javascript, http://stackoverflow.com/questions/7312468/javascript-round-to-a-number-of-decimal-places-but-strip-extra-zeros, http://stackoverflow.com/questions/15762768/javascript-math-round-to-two-decimal-places, ... (not enough characters left) – rid Sep 25 '13 at 12:27
  • can u tell me how can i fix in my code – user2468472 Sep 25 '13 at 12:29
  • 3
    @user2468472 Not enough links yet? – JJJ Sep 25 '13 at 12:29

3 Answers3

0

You can use the .toFixed function.

If you wish to display only 3 decimal places, use .toFixed(3) to your result.

Example

var num = 15.454182;
alert(num.toFixed(3)); // 15.454 
Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
0

You can use toFixed(3) to do this for you. so your code would be:

document.form.sum.value = ((document.form.sum1.value -0) / (document.form.sum2.value -0)).toFixed(3);
box86rowh
  • 3,415
  • 2
  • 26
  • 37
0

This should work.

function updatesum() {
    var sum = (document.form.sum1.value -0) / (document.form.sum2.value -0);
    document.form.sum.value = sum.toFixed(3);
}
stafffan
  • 482
  • 6
  • 17