最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce offtopic - Format number to 2 decimal places

programmeradmin2浏览0评论

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)

  1. 暂无评论