In this Salesforce tutorial, we will learn about the Salesforce ROUND() function. We will also study the syntax for this function as well as numerous Salesforce examples from real-world organizations.
Recently, I was working in the finance department of a multinational company that sells electronic gadgets. To manage their Customer Relationship Management and sales data, they use Salesforce. One day I got the task of calculating the total revenue for each sales transaction and rounding it to the nearest whole amount.
As a solution, I discovered that this Salesforce tool provides us with the function named “ROUND” which helps in rounding the nearest number to a number that we specify.
So, If you want to understand how to use the ROUND() function in Salesforce Lightning and Salesforce Classic, let’s go into further depth and explore.
ROUND Function in Salesforce
The ROUND() function in Salesforce is the mathematical function available in Salesforce that is used to carry out mathematical calculations. In basic terms, the ROUND() function rounds a number to a specified number of digits.
In addition, the ROUND() function only supports numerical data types like Integers, Decimals, and Currency. However, if you attempt to use a text, date, or other non-numeric data type, an error will result.
The syntax of the ROUND() function is as follows:
Here, the number is the value whose rounded value we want to find and the num_digits is the value to which the number is rounded off. The value of the parameter number can be a field, a constant number, or a complex formula.
For a better understanding of how the ROUND function works, let’s look at an example.
As I mentioned above, I need to figure out the total revenue for each sales transaction and round it to the nearest whole amount. I will therefore utilize Salesforce ROUND() method for this. The formula is as follows:
With this, we learned the syntax of the ROUND() function as well as an example. We’ll now look at how to use the ROUND() function in Salesforce Lightning.
How to use ROUND Function in Salesforce Lightning
The following are the steps to use the ROUND() function in Salesforce Lightning:
Step 1: Open Salesforce in Lightning mode and click the “Gear Icon” in the top right corner of the screen. Click “Setup” in the dropdown menu to continue.
Step 2: After choosing the Setup option, the setup screen is displayed. The “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.
Step 3: After clicking it, the object manager page is displayed. We can see a lot of the objects here. To find the object we wish to apply the ROUND() function to, search in the search field. In this case, I search for the “Price Book” object because I need to round the price to the nearest value.
Step 4: To access the “Price Book” object page, click the Price Book item.
Step 5: The “Field & Relationship” option is located under this price book object page in the details area on the left side of the page. From the menu, choose “Field & Relationship”.
Step 6: After choosing the field and relationship option, the field and relationship page is displayed. On the field and relationship page, click the “New” button at the top.
Step 7: Click the new button, and the data type page is to be opened. There are many various types of field types on this page. In this instance, I select the “Formula” data type field because the advanced formula will make use of the ROUND function.
Step 8: To go to the next step, click the “Next” button.
Step 9: After clicking the next button, the screen for choosing the output type displays. 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. In this instance, I typed “Rounded Price” into the field label.
Step 10: Select the “Output Data Type” for the field where the outcome will be saved. In this instance, I check the radio button next to the “Currency” data type to get the formula return type as a currency and set the “Decimal Place” to 1.
Step 11: Move to the next, click on the “Next” button.
Step 12: Enter the ROUND() function formula in the advanced formula editor. In this case, I want to round the book’s price using the ROUND function. The formula reads as follows:
ROUND(Price__c * 20, 0) / 20
- In this formula, the price field is multiplied by 20.
- Then, the result is rounded to the next whole number using the ROUND function.
- After that, the price is then rounded to the nearest value by dividing the rounded amount by 20.
Step 13: Select “Check Syntax” to validate the formula and ensure there are no errors.
Step 14: Enter the “Description” and “Help text” as well as “Handle the empty field” which is optional information.
Step 15: Click the “Next” button to move to the formula field’s security stage.
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.
Because 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: After configuring the field-level security, add the custom field to the “Page Layout”. Select the page layout that includes this field. The field won’t show up on any pages if we do not choose a page layout.
Step 18: Click the “Save” button to save the formula field.
We can use the formula field once we have created it. Let’s look at an example:
- Open the “Price Book” Tab and create a new book price with the field “Price”.
- The “Rounded Price” field, which displays the output of the ROUND() function, then appears when you click on the Details Section.
As a result, we now understand how to use the ROUND() Function in Salesforce Lightning. Now, we’ll look at how to use the ROUND() Function in Salesforce Classic.
How to use ROUND Function in Salesforce Classic
The following are the steps to use the ROUND() 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 this selection of profile pictures. Click on it.
Step 2: Next, select “Setup” from the menu.
Step 3: After choosing the setup option, the setup screen is displayed. Now navigate to the “Build” section. Next, click “Customize” and choose the object for whose field we want to use the ROUND() function. Since I need to know the accurate shipping charges by rounding the order weight, I opt for the “Orders” object in this case.
Step 4: From the drop-down menu, choose “Orders”. There is a field option available and a drop-down list is visible. Click “Fields” from the drop-down menu.
Step 5: After choosing the fields option, the order custom field page is displayed. At the bottom of the page is a section labeled “Order a custom field and a relationship”. Simply select “New” to create a new field.
Step 6: Clicking the new button opens the data type page. There are various types of fields type on the page. I am selecting the “Formula” data type field in this instance.
Step 7: Click the “Next” button to move on to the following step.
Step 8: After choosing the next button, the “Choose Output Type” window opens. To input the information, complete the “Field Label” and “Field Name” (which are pre-filled when you click on the field). I typed “Shipping Cost” into the field label in this instance.
Step 9: Select the “Output Data Type” field where the outcome will be saved. In this instance, I set the “Decimal Place” to 0 and check the radio button next to the “Currency” data type to get the formula return type as a currency.
Step 10: Click the “Next” button to move on to another step.
Step 11: Next, fill out the advanced formula editor with the ROUND() function formula. In this instance, I want to use the ROUND function to determine the shipping charges of the order. The formula for the equation is as follows:
ROUND(Order_Weight__c, 0) * Fixed_Shipping_Rate__c
- Here, we pass the Order_Weight__c field to the ROUND function as we want to round the order weight to the nearest value up to the specific number 0.
- Then, we multiply the Fixed_Shipping_Rate__c field with the rounded value of the order weight of the order to get the shipping cost of the order as per the weight of the order.
Step 12: To verify the formula and make sure there are no mistakes, click “Check Syntax”.
Step 13: If you would like, define the “Description” and “Help text” as well as “Handle the empty field”.
Step 14: Click the “Next” button to go to the formula field’s security page.
Step 15: Make “Field-Level Security” available. Choose the profiles to whom you wish to provide permission for editing field-level security. If field-level security is not specified, the field will be hidden from all profiles.
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 won’t 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 order with the field “Order_Weight__c” and “Fix_Shipping_Rate__c” by opening the Orders Tab.
- Click on the Details section after that, and the “Shipping Cost” field will display the ROUND() function output.
We now understand how to use the ROUND() Function in Salesforce Classic.
In conclusion, we have learned that the Salesforce ROUND() function is an effective way to obtain the number that is nearest to the one we specify, limiting the new number to the specified digits. Moreover, we have learned the ROUND() function syntax and a number of real-world business scenarios.
In addition, we also covered in detail the steps for using the ROUND() Function in Salesforce Lightning and Salesforce Classic.
You may like to read:
- PI() Function in Salesforce
- MOD() Function in Salesforce | Calculate remainder in Salesforce
- TAN() Function in Salesforce
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.