Use num.toFixed(d) to convert a number into the String representation of that number in base 10 with d digits after the decimal point, in this case,
margin_total.toFixed(3);
Use num.toFixed(d) to convert a number into the String representation of that number in base 10 with d digits after the decimal point, in this case,
margin_total.toFixed(3);