how to add price format to email template using suitelet file

we can change the price format for the amount with the function we need to call the function when we need that format

JavaScript function:

function formatCurrency(priceStr) {
               try {
                  var price = parseFloat(priceStr); 
                  if (isNaN(price)) {
                  return priceStr;
                  }
                  var [integerPart, decimalPart] = price.toFixed(2).toString().split(".");
                  integerPart = integerPart.replace(/B(?=(d{3})+(?!d))/g, ",");
                  var formattedPrice = `$${integerPart}.${decimalPart}`;
                  return formattedPrice;
                  } catch (err) {
                     log.debug('error@formatCurrency', err)
               }
            }

then we need to call the function where its required

 <td style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.q1_invoiceamount) || "$0.00"}</td>
    <td style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.q2_invoiceamount) || "$0.00"}</td>
    <td style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.q3_invoiceamount) || "$0.00"}</td>
    <td style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.q4_invoiceamount) || "$0.00"}</td>
    <td class="red-header" style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.totalInvoiceAmount) || "$0.00"}</td>
    <td class="red-header" style="border: 1px solid #ddd; text-align: center; padding: 15px; font-family: arial, sans-serif;">${formatCurrency(objectString.totalInvoiceAmount) || "$0.00"}</td>
</tr>

Leave a comment

Your email address will not be published. Required fields are marked *