Format number to 2 decimal places


I have created a custom product field which is an auto-calculated field, which is saved to the meta data upon save.
The calculation of the field is carried out live using javascript/jQuery.
However, the calculation is not formating the figure to 2 decimal places:

        jQuery(document).ready(function(jQuery) {
            function compute() {
                var a = jQuery('#_regular_price').val();
                var b = jQuery('#_weight').val();
                var total = a / b;
                var totalformatted = total.toFixed(2);
            jQuery('#_regular_price, #_weight').change(compute);

What am I doing wrong in my code for why this is not working?

, , iamonstage 7 months 0 Answers 66 views 0

Leave an answer