Skip to main content
May 11, 2021 2:44 PM UTC
Solved

Formatting number to two decimal places

Hello,

 

I'm working in the HTML for an email creative, trying to force a number field <%= targetData.price %> to two decimal places. It comes through as the lowest number of decimals at the moment ("9" or "12.5". I've used formatDate before, but can't seem to find anything on formatting numbers.

 

Any help would be greatly appreciated.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Manoj_Kumar
Manoj_KumarAccepted solution
Community Advisor
May 11, 2021 2:50 PM UTC

Hello @jonmay1 

 

You can use the javascript to limit the decimal numbers

 

1. Create a span element in the HTML where you want to print the price for eg.

Here is the product price: <span id="productPrice"></span>

2. Then in the javascript you can do this.

<script> var productPrice=<%= targetData.price %>; var productPriceDecimalLimit=productPrice.toFixed(2); /// Here 2 is the deimal places document.getElementById('productPrice').innerHTML=productPriceDecimalLimit; </script>

 

Let me know if that works.

 

 

Manoj  | https://themartech.pro

2 replies

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
May 11, 2021 2:50 PM UTC

Hello @jonmay1 

 

You can use the javascript to limit the decimal numbers

 

1. Create a span element in the HTML where you want to print the price for eg.

Here is the product price: <span id="productPrice"></span>

2. Then in the javascript you can do this.

<script> var productPrice=<%= targetData.price %>; var productPriceDecimalLimit=productPrice.toFixed(2); /// Here 2 is the deimal places document.getElementById('productPrice').innerHTML=productPriceDecimalLimit; </script>

 

Let me know if that works.

 

 

Translate
Manoj  | https://themartech.pro
JonMay1Author
May 11, 2021 3:32 PM UTC
Fab, thank you very much! Worked great.
Translate