The FormatNumber function is very similar to the FormatCurrency function. In fact, the FormatNumber function can be used in place of the FormatCurrency function.
The FormatNumber function to properly format number values by rounding the number up to fewer decimal places.
Use case: you receive a number value from a data source with just number value that has a long number of characters after the decimal place, i.e. “423.234234234235”. You can use the function to properly format this to a whole number of “423” or any number of characters after the decimal place. You can even format the number to be a currency format. You’ll need to use this list of ISO Country Codes compatible with Salesforce Marketing Cloud. FormatNumber
Syntax:
FormatNumber(1,2,3)
1 = Numerical value to apply number formatting
2 = Number format type. See below:
C – Currency, i.e. $423.23
D – Decimal, i.e. 423.23
E – Exponential, i.e. 4.232342E+002
F – Fixed point, i.e. 423.23
G – General, i.e. 423.234234234235
N – Number, i.e. 423.23
P – Percent, i.e. 42,323.42%
R – Round-Trip (allows string to be parsed back to number), i.e. 423.234234234235
X – Hexadecimal, (only works with whole numbers)
(Optional) Add a number after the letter above to designate how many characters after the decimal place. For example, if you wanted a whole number, you could use N0 (see below)
3 = ISO Country Code. See list of SFMC Compatible ISO Country Codes above
Example:
%%[
set @numberValue = “423.234234234235”
]%%
%%=FormatNumber(@numberValue, “N0”, “en-us”)=%%
Output:
423
Explanation:
In the example above, we start off with the long number value of “423.234234234235”. We use the format type of N for Number and 0 for the number of characters after the decimal place (we want to turn “423.234234234235” into a whole number of “423”FormatNumber
The function rounds the number down to “423” and using the ISO Country Codes compatible with SFMC. Note that the FormatNumber function can be used for whole numbers or decimals. The datatype for these values should be a number datatype or decimal or you can hardcode the numbers as it is shown in the example above.FormatCurrency
Related function is the FormatCurrency function.