0

I would like the sub total value to be toFixed(2), so that the sub-total input will display "864.91" instead of "864.9100000000001".

Also, I have 2 inputs below sub-total called GST and total_price.

Basically, GST should take the sub-total value and multiply it by (5/100) and display it in the GST input value.

The total price should take the GST value and the sub-total value, add them together, and display the number in the total_price input value.

  1. Any ideas on what code I can use to do this?
  2. I would also like all values to be no longer than 2 decimal places like the sub-total input value (864.91 instead of 864.9100000...).

Here is the code I have so far:

function selectProduct(sel) {
    var end = sel.value;
    var typeId = sel.id;
        $.ajax({    //create an ajax request to load_page.php
            type: "GET",
            url: "ajax_all.php?from=pos_product&name="+end,
            dataType: "html",   //expect html to be returned
            success: function(response){
                var sub_total = $("#sub-total").val();
                $("#sub-total").val(+sub_total + +response);

            }
    });
}

Thank you for any help, all help is greatly appreciated.

xerx593
  • 12,237
  • 5
  • 33
  • 64
Kelsey
  • 913
  • 3
  • 19
  • 41
  • http://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-in-javascript – xerx593 Apr 20 '15 at 17:57
  • Thanks but this is working with money, so I don't want full dollars, but cents as well. (I.e. $4.52, not $4) – Kelsey Apr 20 '15 at 18:00
  • 1
    sorry, i edited my comment, please re-view (regarding the 2nd aspect of your question) – xerx593 Apr 20 '15 at 18:04

0 Answers0