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."

Attribution to: Shane McLaughlin

# Possible Suggestion/Solution #1

Here's the trick. You have to

- take the "whole numbers" portion
- Round down
- add the decimal places using text
- subtract to get the decimal portion
- multiply that by 10^[how many digits you want to force]
- 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.

Attribution to: Shane McLaughlin

This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5026