When I use the text formula, salesforce doesn't respect my decimal place formatting. For example,

Field A has 4 places to the right of the decimal. It shows up nicely on the page as 0.4000

If I'm generating a complex string based on the field, I might want to have a formula field equal to:

"The price is $" & text(Field_a__c) & ", buddy."

Unfortunately, this produces, "The price is $.4, buddy."

  • I just spent 30 minutes trying to find a good way to do this, so I thought I would share it with all of you. – Shane McLaughlin Dec 4 '12 at 2:19

Here's the trick. You have to

  1. take the "whole numbers" portion
  2. Round down
  3. add the decimal places using text
  4. subtract to get the decimal portion
  5. multiply that by 10^[how many digits you want to force]
  6. pad the left hand side of the digits after the decimal point with zeroes to add up to the number of decimal places you need

text(floor(Field_a__c)) &"."& lpad(text((Field_a__c-floor(Field_a__c))*100),2,"0")

In this example, you'll get output like "157.50" if your number is 157.5, "147.00" if your number is 147, and "127.01" if your number is 127.01.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.