In this Salesforce tutorial, we will learn how to use the TRUNC() function in Salesforce to truncate a number to a specified number of digits. We will also learn its syntax and a few useful examples.
I recently worked in a multinational company that manages their Customer Relationship Management and sales data, using Salesforce. One day I got the task of calculating the lead age in whole days.
As a solution, I discovered that this Salesforce tool provides us with the function named “TRUNC” which helps to remove the decimal part of the age and shows the age as whole days.
So, If you want to understand how to use the TRUNC() function in Salesforce Lightning and Salesforce Classic, let’s explore further.
TRUNC Function in Salesforce
The TRUNC() function in Salesforce is the mathematical function available in Salesforce that is used to carry out mathematical calculations. In basic terms, the TRUNC() function is used when we need to truncate a number to a specified number of digits.
In simple words, we can say that the TRUNC() function in Salesforce is used to round down a numerical value to the nearest whole number or a given number of decimal places. Basically, it truncates the decimal part of the number and returns the integer part.
In addition, the TRUNC() function only supports numerical data types like Integers, Decimals, and Currency. However, an error will result if you try to use a text, date, or other non-numeric data type.
The syntax of the TRUNC() function is as follows:
TRUNC(number,num_digits)
Here:
- number: It specifies the value that you want to truncate.
- num_digits: It specifies the number of decimal places to which you want to round the number, but it is an optional parameter. If not specified, the function rounds numbers to the nearest whole number.
For a better understanding of how the TRUNC function works, let’s look at an example.
As I mentioned above, I need to find the lead age in whole days. Therefore, I will utilize Salesforce TRUNC() function for this. The formula is as given below:
TRUNC(Age__c, 0)
With this, we learned the syntax of the TRUNC() function as well as an example. We’ll now look at how to use the TRUNC() function in Salesforce Lightning.
Read TEXT() Function in Salesforce
How to use TRUNC Function in Salesforce Lightning
The following are the steps to use the TRUNC() function in Salesforce Lightning.
Step 1: Open Salesforce Lightning mode. Next, click the “Gear Icon” in the top right corner of the page. Click “Setup” from the dropdown menu to continue.

Step 2: The setup page is opened after selecting the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.

Step 3: The object manager page is opened after you click it. There are numerous objects seen here. Use the quick find search field to look for the item on which we want to use the TRUNC() function. In this instance, I look for the “Product” object because I need to calculate the shipping cost of the product based on the rounded weight of the product.
Step 4: Now click the “Product” object to move to the product object page.

Step 5: Under this product object page, on the left side of the page, the “Field & Relationship” option is found in the details section. Select “Field & Relationship” from the menu.
Step 6: The field and relationships page is opened after selecting the field and relationship option. Click the “New” button at the top of the field and relationship page.

Step 7: The field type page is opened after clicking the new button. The page contains a wide variety of field types. In this case, I choose the “Formula” field type field, as I want to use the TRUNC function in the advanced formula.
Step 8: Click the “Next” button to move on to the next step.

Step 9: The choose output type screen appears after clicking the next button. Enter the information now by filling out the “Field Label” and the “Field Name”, which is automatically filled in when you put the cursor on the field name. In this instance, I typed “Shipping Charges” into the field label.
Step 10: Choose the “Output Data Type” for the field in which we want to store the result. In this case, I check the radio button in front of the “Currency” data type to receive the formula return type as a currency, and I also set the “Decimal Place” to 3.
Step 11: Move to the next, click on the “Next” button.

Step 12: Go to the advanced formula editor and enter the TRUNC() function formula there. In this instance, I want to use the TRUNC function to calculate the shipping cost of the product based on the rounded weight of the product. The formula is as follows:
TRUNC(Weight__c, 1)
- Here, we round down the value of the weight of the product to one decimal place using the TRUNC() function.
- Basically, this function removes the extra decimal digits and truncates the resultant value to one decimal place.
Step 13: To validate the formula and make sure there are no mistakes, click the “Check Syntax” option.
Step 14: Optionally, we may define the “Description” and “Help text” as well as “Handle the empty field” if we like.
Step 15: Click on the “Next” button to go to the security setup for the formula field.

Step 16: In this step, establish “Field-Level Security”. Now choose the profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, the field will be hidden from all profiles.
As I want it to be visible to all profiles, I have chosen “Visible” in this instance. After that, click the “Next” button located at the top.

Step 17: Add the custom field to the “Page Layout” after setting up the field-level security. Pick the page layout that has this field in it. If we do not select a layout, the field will not appear on any pages.
Step 18: To save the formula field, click the “Save” button.

We can use the formula field once we have created it. Let’s look at an example:
- Open the Products Tab and create a new product with the field Weight.
- The Shipping Charges field, which displays the output of the TRUNC() function, then appears when you click on the Details Section.

As a result, we now understand how to use the TRUNC function in Salesforce Lightning. Now, we will look at how to use the TRUNC function in Salesforce Classic.
Read ASCII() Function in Salesforce
How to use TRUNC Function in Salesforce Classic
The following are the steps to use the TRUNC() function in Salesforce Classic.
Step 1: Log in to your Salesforce account first, after you are logged in, the Salesforce Lightning Edition should already be open. Click “Profile Picture” once you are in Salesforce Lightning. The drop-down menu for the profile photo is available. There is a “Switch To Salesforce Classic” option below the selection of profile picture. Click on it.

Step 2: Next, click on the “Setup” option from the menu.

Step 3: The setup page is opened after selecting the setup option. Go down to the “Build” section now. Select the object for whose field we want to use the TRUNC() function under the “Customize” dropdown. In this instance, I choose the “Campaign” object since I need to round down the percentage of the campaign budget spent.
Step 4: Select “Campaign” from the drop-down menu. The drop-down list is available, and under it, there is a field option. Select “Fields” from the menu.

Step 5: The product custom field page is opened after selecting the fields option. There is a section titled “Campaign custom field and relationship” at the bottom of the page. Simply click the “New” button to add a new field.

Step 6: The field type page is opened after clicking the new button. The page contains a wide variety of data types. In this case, I am choosing the “Formula” data type field.
Step 7: Click the “Next” button to move on to the following step.

Step 8: The “Choose Output Type” window appears after selecting the next button. Fill out the “Field Label” and “Field Name” (which are pre-filled when you click on the field name) to enter the information. In this case, I entered “Campaign Budget” into the field label.
Step 9: Choose the “Output Data Type” for the field in which we want to store the result. In this case, I check the radio button in front of the “Currency” data type to receive the formula return type as a currency, and I also set the “Decimal Place” to 1.
Step 10: Click the “Next” button to move on to another step.

Step 11: Next, enter the TRUNC() function formula in the advanced formula editor. In this case, I wish to utilize the TRUNC function, to calculate the round-down percentage value of the campaign budget spent. The formula reads as follows:
TRUNC( ActualCost / BudgetedCost * 100, 0)
- Here, we divide the actual cost of the campaign budget by the budgeted cost of the campaign, and then to convert this to a percentage we multiply the resultant value by 100.
- Next, to round down the resultant value to the nearest whole number, we passed the result to the TRUNC function and set its num digits to 0 to truncate the result to zero decimal places.
Step 12: Click “Check Syntax” to validate the formula and ensure there are no errors.
Step 13: Define the “Description” and “Help text” as well as “Handle the empty field” if you would like.
Step 14: To access the security page for the formula field, click the “Next” button.

Step 15: Establish “Field-Level Security”. Select the profiles to whom you want to grant field-level security editing access. The field will be hidden from all profiles if field-level security is not set.
I have selected “Visible” in this case because I want it to be visible to all profiles. In order to continue, click the “Next” button at the top.

Step 16: After configuring the field-level security, add the custom field to the “Page Layout”. Choose the page layout that includes this field. The field would not show up on any pages if we choose not to select a layout.
Step 17: To save the formula field, click the “Save” button.

Once we have established the formula field, we may use it. Let’s examine an illustration:
- Create a new campaign with the fields Actual Cost, and Budget Cost by opening the Campaign Tab.
- Click on the Details section after that, and the Campaign Budget field will display the TRUNC() function output.

We now understand how to use the TRUNC() function in Salesforce Classic.
Conclusion
In conclusion, we have learned that the Salesforce function TRUNC() is helpful for handling numerical data and to truncates a number to a specified number of digits.
We also learned that we can apply this function in a number of real-world scenarios, including “Price Book Discount”, “Case Response Time”, “Lead Conversion Rate”, etc.
Additionally, we completely understand the Salesforce TRUNC() function syntax and approach for using the TRUNC function in both Salesforce Lightning and Salesforce Classic.
You may like to read:
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.