1

I want to round the result coming from "document.getElementById('Edit_total_price').value = result1;" to two decimal postions in javaScript. this is my overall code

function edit_calculate() {
            var myBox1 = document.getElementById('Editprevious_reading').value;
            var myBox2 = document.getElementById('Editcurrent_reading').value;
            var myBox3 = document.getElementById('Edit_total_sale').value;
            var Edit_total_sale = document.getElementById('Edit_total_sale').value;
            var myResult = myBox2 - myBox1;
            var result1 = document.getElementById('price').value * myResult;
            document.getElementById('Edit_total_sale').value = myResult;
            document.getElementById('Edit_total_price').value = result1;

        }
Óscar Andreu
  • 1,630
  • 13
  • 32
  • Personally, when it comes to prices, I use a library called *accounting.js*. I would recommend looking into that, unless you're super persistant in coming up with your own solution. Here's a link: http://openexchangerates.github.io/accounting.js/ – Martin Sep 12 '18 at 06:03
  • 2
    try this `Math.round(num * 100) / 10`. Also refer [link](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary) – Nareen Babu Sep 12 '18 at 06:03
  • 1
    Remember to take notes of the comments given in @user2932057's link. It's rather important. There are so many factors when dealing with this issue specifically, although on the surface, it seems like a simple task. This is also mainly why I provided a library for it. – Martin Sep 12 '18 at 06:09
  • Yes, I agree @Martin – Nareen Babu Sep 12 '18 at 06:11

0 Answers0