Format number to 2 decimal places
Question
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('#shop_price_per_kg').val(totalformatted);
}
jQuery('#_regular_price, #_weight').change(compute);
});
What am I doing wrong in my code for why this is not working?
0
javascript, jquery, woocommerce
7 months
0 Answers
66 views
0
Leave an answer
You must login or register to add a new answer .