Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
A technical diagram illustrating how to retain leading zeros of decimal places in Salesforce email templates
Admin

Retain zeros of decimal places in email templates

The short answer

A Salesforce email template rounds any number with more than three decimal digits and drops the zeros on the end. To hold a fixed number of decimal places, build a text formula field that rounds the value and pads the fractional part back out, then reference that field in the template.

Key takeaways Move the value into a text formula field so the email template stops rounding to three decimal places and dropping the zeros on the end. Pull out the whole-number part and the decimal point with the LEFT, TEXT, and FIND functions. Pad the fractional digits with RPAD, RIGHT, and LEN so the decimal part is always the same length. Change the digit argument in ROUND and RPAD to show a different number of decimal places.

Recently while working with email template, I struggled lot to show just a number field having 6 decimal places on email template. The requirement was to show 6 decimal places leading zeros.

For example, if the decimal field value is 45.7891 then it should show 45.789100. The number field was set to 6 decimal places, however it was showing 45.789 on email template.

Two things I noticed, those are:

  • More than 3 decimal digits are automatically rounded to 3 decimal digits.
  • If there are leading zeros, they simply gets ignored, like if the number is, 4.100, it will show as 4.1 on mail template.

To tackle this, I had to built formula field with following formula which outputs the number value in text format and then placed the field in email template.

Formula

LEFT(TEXT(ROUND(decimal_value__c, 6)), FIND('.', TEXT(ROUND(decimal_value__c, 6))))+RPAD(RIGHT(TEXT(ROUND(decimal_value__c, 6)),  LEN(TEXT(ROUND(decimal_value__c, 6))) - FIND('.', TEXT(ROUND(decimal_value__c, 6)))), 6, '0')

Considerations

  • decimal_value__c is a number field with 6 decimal places.

Explaination

  • ROUND(decimal_value__c, 6) : Rounds the number with specified decimal places, here its 6.
  • TEXT(ROUND(decimal_value__c, 6)) : Converted whole number in text format
  • FIND('.', TEXT(ROUND(decimal_value__c, 6))) : To find the position of decimal point in text format of digit.
  • LEFT(TEXT(ROUND(decimal_value__c, 6)), FIND('.', TEXT(ROUND(decimal_value__c, 6)))) : Gives left side of number. If the number is 458.669, this formula outputs as 458
  • LEN(TEXT(ROUND(decimal_value__c, 6))) - FIND('.', TEXT(ROUND(decimal_value__c, 6))) : Finds number of digits after decimal place. for 458.669, it outputs as 3.
  • RPAD(RIGHT(TEXT(ROUND(decimal_value__c, 6)), LEN(TEXT(ROUND(decimal_value__c, 6))) - FIND('.', TEXT(ROUND(decimal_value__c, 6)))), 6, '0') : It will always make sure to have numberof digits as 6, so if value is 669, will output as 669000
  • Final Formula : Concatenate both values, final value will be 458.669000

Replace 6 with the number of digits you want to show on email template.

Frequently asked questions

Why does Salesforce truncate decimal places in email templates?

An email template rounds a number with more than three decimal digits to three decimal places, and it drops any zeros on the end.

How do you display trailing zeros for decimal fields in Salesforce email templates?

Create a formula field with a text return type that rounds the number and uses RPAD to pad the fractional part with zeros, then reference that field in the email template instead of the number field.

How do you change the number of decimal places shown by the formula?

Swap the 6 in the ROUND and RPAD functions for the number of decimal digits you want to show.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment