简体   繁体   中英

Change Output to 2 decimal places

I have this JS file. This snippet will display Delivery Charge but its in 4 decimal places. I want it to display only two decimal places. How to change the code?

 if (val.order_id > 0) { html += '<div class="col text-right">'; html += "<b class='amout'>" + val.order_total_amount + "</b>"; html += "<b class='charge_thaitop " + val.payment_type_raw + "'>" + getTrans('Delivery Fee ', 'deliver_fee') + getTrans('RM', 'MYR') + val.delivery_charge + "</b>"; html += '</div>'; }

The + val.delivery_charge+ will output the number but currently its in 4 decimal places. I want it in two decimal places only. Refer the output in the picture below:

output in red rectangle

Thanks

You can convert it to a string and count below the comma and check if ther are more or less than 2 chars.

Or method .toFixed(2)

I have found the solutions.

Sorry im not familiar with this JS.

But i put prettyPrice(val.delivery_charge) and its worked.

Thanks for the suggestion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM