Do you want to format a number in Power Automate? Here, I will explain how to use formatnumber() function in Power Automate to format a number. Then, I will show you how to use the format number Power Automate flow action.
Power Automate provides two ways to format a number inside a flow
- formatNumber() function
- Format Number action
Let us check with examples.
formatNumber() in Power Automate
In Power Automate formatNumber() function accepts a number and converts it into the required format; it can be a currency, percentage float, etc.
Here is the formatNumber() expression syntax.
formatNumber(Number, 'format', 'locale')
- Number: This is the number you want to format
- ‘format’: Then the number will get formatted.
- Locale: Provide the locale, while formatting the number as currency[optional]
For example, we need to format the decimal number into percentages; for this, we can use the expression below
- formatNumber(0.6, 0.00%), it returns 60.00%.
- formatNumber(0.6, 0%), it returns 60%.
Now, let’s see how to use the formateNumber function in a flow in Power Automate.
1. Open Power Automate, click on + Create, and then select “Instant cloud flow“
2. Then provide the flow name and select the “Manually trigger a flow” action. Then click on Create.
3. Then click on the +Add an input, then select the Number option, and the Number field is added to the action.
4. Now, we will convert the given decimal number to a percentage. For this, click on Add an action and select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
formatNumber(triggerBody()['number'],'0.00%')
5. Now save the flow and run the flow manually, then provide any decimal number. You can see the number is formatted to percentage.
To convert the decimal number 0.6 to percentage 60%, use the below expression in the compose action input field.
formatNumber(0.6, 0%), it returns 60%.
Now, if you run the flow manually and provide the input number as 0.6, you can see the output as 60%.
This is how to use the formatNumber() function in Power Automate.
Format Number action in Power Automate
Here, we will see how to use the Format Number flow action in Power Automate.
The format number action also works in the same way as the formatNumber() function works. The format action also takes the same input i.e. Number, format, and Locale.
Here is an example.
1. Open Power Automate Cloud flow, then select the instant cloud flow.
2. Then, provide the flow name and select the “Manually trigger a flow” action. Then click on Create.
3. Now, we will convert the given decimal number to a percentage. For this, click on Add an action and select Format Number action. Then provide the below information:
- Number: Provide the number as 0.6
- Format: Provide the format as 0.00%
4. Now save the flow and run the flow manually, then provide any decimal number. You can see the number is formatted to percentage.
To convert the decimal number 0.6 to percentage 60% in Format number action. For this, in the format number action, provide the below information:
- Number: Provide the number as 0.6
- Format: Provide the format as 0%
Now, if you run the flow manually, you can see the output as 60%.
This is how to use the Format Number action in Power Automate.
List of formats to Format number in Power Automate
Here, we will list some of the formats to format the number in Power Automate
Following format to format number in Power Automate.
1. Format number to decimal
The “D” (or decimal) format specifier is used to convert a number into a string consisting of decimal digits (0-9). If the number is negative, it will be prefixed with a minus sign.
It’s important to note that this format specifier is applicable only to integral types.
The precision specifier plays a role in indicating the minimum number of digits you want in the resulting string.
If necessary, the number will be padded with leading zeros to meet the digit count specified by the precision specifier.
If you don’t specify a precision specifier, by default it will include the minimum number of digits required to represent the integer without any leading zeros.
Number | Format | Expression | Result |
---|---|---|---|
234 | D | formatNumber(234, ‘D’) | 234 |
234 | D4 | formatNumber(234, ‘D4’) | 0234 |
234 | D8 | formatNumber(234, ‘D8’) | 00000234 |
-234 | D4 | formatNumber(-234, ‘D’) | -0234 |
The Exponential “E” format changes a number into a string that looks like this: “-d.ddd…E+ddd” or “-d.ddd…e+ddd.” Each “d” is a digit (0-9). If the number is negative, it starts with a minus sign. There’s always one digit before the dot.
The precision specifier tells us how many digits we want after the dot. If we don’t say, it’s six by default.
The format specifier’s capitalization decides whether we use “E” or “e” for the exponent part. The exponent always has a plus or minus sign and at least three digits. If needed, zeros are added to make it three digits long.
Number | Format | Expression | Result |
---|---|---|---|
234 | E | formatNumber(234, ‘E’) | 2.340000E+002 |
234 | E4 | formatNumber(234, ‘E4’) | 2.3400E+002 |
234 | E8 | formatNumber(234, ‘E8’) | 2.34000000E+002 |
-234 | E8 | formatNumber(-234, ‘E8’) | -2.34000000E+002 |
3. Format number to Fixed point specifier
The Fixed Point “F” format takes a number and turns it into a string that looks like this: “-ddd.ddd…”. Each “d” is a digit from 0 to 9. If the number is negative, it starts with a minus sign.
The precision specifier tells us how many digits we want after the decimal point.
Number | Format | Expression | Result |
---|---|---|---|
234 | F | formatNumber(234, ‘F’) | 234.00 |
234 | F4 | formatNumber(234, ‘F4’) | 234.0000 |
234 | F8 | formatNumber(234, ‘F8’) | 234.00000000 |
234 | F0 | formatNumber(234, ‘F0’) | 234 |
-234 | F4 | formatNumber(-234, ‘F4’) | -234.00000000 |
4. Format number to General Format
The General “G” format changes a number into a shorter version, either with a fixed number of decimal places or in scientific notation. Which one it picks depends on the number and any instructions you provide.
If you specify a precision (how many important digits to keep), it will follow that. Otherwise, it uses a default precision based on the type of the number.
Number | Format | Expression | Result |
---|---|---|---|
234.56 | G | formatNumber(234.56, ‘G’) | 234.56 |
234 | G2 | formatNumber(234, ‘G2’) | 2.3E+02 |
000.234 | G7 | formatNumber(000.234, ‘G7’) | 0.234 |
5. Format number as Percentage Format
The Percentage “P” format takes a number, multiplies it by 100, and turns it into a string that shows it as a percentage. The precision specifier tells us how many decimal places we want to include in that percentage.
Number | Format | Expression | Result |
---|---|---|---|
234.56 | P | formatNumber(234.56, ‘P’) | 23,456.00 % |
.23456 | P with locale ‘hr-HR’ | formatNumber(.23456,’P’,’hr-HR’) | 23,46% |
.234 | P2 | formatNumber(.234, ‘P2’) | 23.40% |
6. Format Number as hexadecimal
The Hexadecimal “X” format accepts a number and turns it into a string which is of hexadecimal digits. These are the characters 0-9 and A-F (or a-f).
Also, you can choose whether you want the letters to be in uppercase (“X”) or lowercase (“x”). For example, “X” gives you “ABCDEF,” and “x” gives you “abcdef.”
This format only works for whole numbers. The precision specifier tells us how many digits you want in the string. If you need more digits, zeros are added to the beginning of the string to match the specified number.
Number | Format | Expression | Result |
---|---|---|---|
234 | X | formatNumber(234, ‘X’) | EA |
234 | x | formatNumber(234,’X’) | ea |
23456 | X2 | formatNumber(23456, ‘X2’) | 5BA0 |
7. Format Number as Currency
The Currency “C” format changes a number into a string that looks like a currency amount. It’s like writing money values, with a symbol like “$” or “€”. The precision specifier tells us how many decimal places you want in that money amount.
Number | Format | Expression | Result |
---|---|---|---|
50 | C | formatNumber(50,’C’) | $50.00 |
50 | C0 | formatNumber(50,’C0′) | $50 |
50 | C1 | formatNumber(50,’C1′) | $50.0 |
12345 | C2 | formatNumber(12345,’C2′) | $12,345.00 |
12345 | C3 | formatNumber(12345,’C3′) | $12,345.000 |
12345 | C with locale ‘de-de’ | formatNumber(12345,’C’,’de-de’) | 12.345,00 € |
8. Custom Numeric string format
You can create your own custom numeric format string, which is made up of one or more custom numeric specifiers. This specifier will format the number and how we want to display the number.
Number | Format | Description | Expression | Result |
---|---|---|---|---|
23.45 | 0 | Replace the zero in the output string with the appropriate digit if it exists; else, zero is displayed. | formatNumber(23.45,’0’) | 23 |
23.89 | # | if a digit is available, replaces the “#” symbol with it; else, the returned string contains no digits. | formatNumber(123.89,’#’) | 124 |
12389 | ##-## | formatNumber(12389,’##-##’) | 123-89 | |
0.6 | % | multiplies a value by 100 and appends a localised percentage symbol to the output string. | formatNumber(0.6,’0.00%’) | 60.00% |
123567 | , | The comma (‘,’) has two roles. First, it separates groups of numbers with a symbol that matches your location. Second, it acts as a way to scale numbers down by a factor of 1000 for each comma you use. | formatNumber(123567,’##,##’) | 123,567 |
This is the list of formats available to format the number in Power Automate. To learn it in more detail, refer to the Standard numeric and Custom numeric formats.
Conclusion
I hope you got an idea of how to use the Power Automate formatNumber() function to format a number to different formats like decimal, currency, etc.
I have also explained how to use the format number flow action in Power Automate. Finally, I have listed down the formats available in the formatNumber() function in Power Automate.
You may like the following tutorials:
- How to Format Numbers to Decimal Places Using Power Automate?
- How to Format Number to Percentage in Power Automate?
- The DateTime String must match ISO 8601 format error in Power Automate
- Format Numbers with Leading Zeros Using Power Automate
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com