How can i round javascript calculations to 2 decimals

Highlighted
Tourist
36 0 1

 

the code below i want to output to 2 d.p as it currently has around 8-10 depending on the result

 

jQuery(function() {
 $('.cal_submit').click(function(){
     var order_total = $('.cal_val').val(),
     m24_mp = order_total * 0.04852,
     m36_mp = order_total * 0.03377,
     m48_mp = order_total * 0.02643,
     m60_mp = order_total * 0.02210,
     m24_wp = m24_mp * 12/52,
     m36_wp = m36_mp * 12/52,
     m48_wp = m48_mp * 12/52,
     m60_wp = m60_mp * 12/52,
     m24_tc = m24_mp * 24,
     m36_tc = m36_mp * 36,
     m48_tc = m48_mp * 48,
     m60_tc = m60_mp * 60,
     m24_tr = m24_tc * 0.19,
     m36_tr = m36_tc * 0.19,
     m48_tr = m48_tc * 0.19,
     m60_tr = m60_tc * 0.19,
     m24_tatr = m24_tc - m24_tr,
     m36_tatr = m36_tc - m36_tr,
     m48_tatr = m48_tc - m48_tr,
     m60_tatr = m60_tc - m60_tr;
     
     $('#m24_mp').html(m24_mp);
     $('#m36_mp').html(m36_mp);
     $('#m48_mp').html(m48_mp);
     $('#m60_mp').html(m60_mp);
     
     $('#m24_wp').html(m24_wp);
     $('#m36_wp').html(m36_wp);
     $('#m48_wp').html(m48_wp);
     $('#m60_wp').html(m60_wp);
     
     $('#m24_tc').html(m24_tc);
     $('#m36_tc').html(m36_tc);
     $('#m48_tc').html(m48_tc);
     $('#m60_tc').html(m60_tc);
     
     $('#m24_tr').html(m24_tr);
     $('#m36_tr').html(m36_tr);
     $('#m48_tr').html(m48_tr);
     $('#m60_tr').html(m60_tr);
     
     $('#m24_tatr').html(m24_tatr);
     $('#m36_tatr').html(m36_tatr);
     $('#m48_tatr').html(m48_tatr);
     $('#m60_tatr').html(m60_tatr);
     
 })
});

 

0 Likes
Highlighted
Shopify Partner
375 46 75

Hi,
you can use toFixed method
so for ex. 

$('#m24_mp').html(m24_mp.toFixed(2));

 

If helpful then please Like and Accept Solution.
Email: suhagiyajivan1992@gmail.com
Skype: jivan.suhagiya
Give a try to Shopify APP: https://apps.shopify.com/checkout-reminder
0 Likes
Highlighted
Tourist
36 0 1

this worked amazing thanks

0 Likes