Format Number In Power Automate

In this Power Automate tutorial, I will explain how to format number in Power Automate.

Microsoft provides a function in Power Automate called formatNumber() that you can use to format a number in Power Automate. Also, you can use the Format Number action in Power Automate.

I will also show you a few examples related to format number in Power Automate:

  • How to format number as currency in Power Automate
  • How to format number to leading zeros in Power Automate
  • Working with Power Automate float decimal places expression
  • Power Automate format number Hexa decimal expression
  • Power Automate format number thousand separator
  • Format number to percentage in Power Automate
  • Power Automate Fixed Point decimal places
  • Power Automate format number expression as exponential format

Power Automate formatNumber() Function

formatnumber() Power Automate is a function that takes a number and formats it into the desired format, which can be a float, currency, percentage or another type of data.

Below is the syntax for the Power Automate format number:

formatNumber(number, 'format', 'locale')

Where,

  • Number: Provide the number that you want to format
  • ‘format’: The number will get formatted
  • Locale: Provide the locale while formatting the number to any different data type [Optional]

Example:

formatNumber([7895], 'C0')                                    // Output - $7895

How to Use Power Automate formatnumber Function

Let’s discuss some of the useful examples using Power Automate format number expression:

Format Number as Currency in Power Automate

Here, I will explain how to work with Power Automate format number as currency.

To define the standard currency format, Power Automate format the number as currency with commas, i.e., ‘C’ format. To get the decimal places after the number, use ‘C’ followed by numbers.

‘C2’ represents the default format concerning ‘C’. Refer to the table below:

NumberFormatExpressionResult
56789CformatNumber(56789,’C’)$56,789.00
56789C0formatNumber(56789,’C0′)$56,789
56789C1formatNumber(56789,’C1′)$56,789.0
56789C2formatNumber(56789,’C2′)$56,789.00
56789C3formatNumber(56789,’C3′)$56,789.000

Follow the below steps:

1. Open the Power Automate Home page, click on + Create -> Instant cloud flow. Give Flow name, and select trigger Manually trigger a flow -> Create.

  • In the trigger, Click Add an input -> Select Number.

2. Now, add an ‘Initialize variable’ flow action and set properties like Name, Type, and Value.

Value: formatNumber(triggerBody()['number'],'C0')
Power Automate format number expression currency

3. In this step, add ‘Compose’ data operation to check the output received from the given expression.

Power Automate format number expression currency format

4. Now, it is time to save and test the flow. Click on Save and Test -> Test Manually.

5. The outputs of the compose data operation will return the formatted number as currency, as shown below:

formatNumber() expression currency format in Power Automate

This is how to get the formatted number as currency with commas inside a Power Automate flow.

Format Number With Leading Zeros in Power Automate

Next, we will see how to work with Power Putomate add leading zeros.

In Power Automate, this can be done by providing a standard ‘D‘ format in formatNumber expression. In the expression, ‘D’ followed by the digit refers to the total number of digits consisting of a provided number.

The below-placed table below will show different formats of digit expression:

NumberFormatExpressionResult
567DformatNumber(567,’D’)567
567D3formatNumber(567,’D0′)567
567D4formatNumber(567,’D1′)0567
567D5formatNumber(567,’D2′)00567
567D6formatNumber(567,’D3′)000567

For that, follow the above-mentioned but only need to change the expression of formatNumber.

1. In the ‘Initialize variable’ flow action, provide details like Name, Type, and Value to convert the string to an integer.

int(triggerBody()['number'])
Power Automate formatNumber expression leading zeros

2. In the Inputs of compose flow action, add the below-given expression to add the leading zeros.

formatNumber(variables('Digit'),'D3')
Power Automate format number leading zeros

3. The output displayed from the compose data operation will show the result below.

FormatNumber() Function add leading Zeros in Power Automate

This way, we can achieve Power Automate format number leading zeros.

How to Use Power Automate Float Decimal Places

To add decimal places for a number, use the format() number function using the standard ‘F‘ format inside a Power Automate flow.

In the expression, ‘F’ followed by the digit refers to the total number of decimals provided. In the formats, ‘F2’ is the default format that resembles the ‘F’ format.

NumberFormatExpressionResult
56789FformatNumber(56789,’F’)56789.00
56789F0formatNumber(56789,’F0′)56789
56789F1formatNumber(56789,’F1′)56789.0
56789F2formatNumber(56789,’F2′)56789.00
56789F3formatNumber(56789,’F3′)56789.000

Follow the below-mentioned points:

1. Provide the formatNumber expression in the value section of the initialized variable.

Value: formatNumber(triggerBody()['number'],'F2')
Power Automate float decimal places formatNumber expression

2. The image below shows the decimal places output from the formatted number.

Power Automate format numbers with decimal

Power Automate Format Number Thousand Separator

A user can format a number separated by commas and configure the number of decimal places using the formatNumber() expression with the standard ‘N‘ format.

The ‘N’ format is similar to the ‘F’ format. In the same way, ‘N’ is followed by a digit, which refers to the total number of decimals provided in it.

NumberFormatExpressionResult
56789NformatNumber(56789,’N’)56,789.00
56789N0formatNumber(56789,’N0′)56,789
56789N1formatNumber(56789,’N1′)56,789.0
56789N2formatNumber(56789,’N2′)56,789.00
56789N3formatNumber(56789,’N3′)56,789.000

1. Give the expression for a thousand separator with commas in the value of an initialized variable.

formatNumber(triggerBody()['number'],'N1')
Power Automate format number thousand separator expression

2. The returns of the formatted number expression will give the number with commas as shown below.

Power Automate format number with comma

How to Format Number to Percentage in Power Automate

We can use the standard ‘P‘ format with the Power Automate format number as a percentage.

Using this, the percentage will be multiplied by 100, and the output will be a string along with the percentage.

In the expression, ‘P’ followed by a digit refers to the number of decimals displayed that should be included in the format.

NumberFormatExpressionResult
0.10PformatNumber(0.10,’N’)10.00%
0.10P0formatNumber(0.10,’N0′)10%
0.10P1formatNumber(0.10,’N1′)10.0%
0.10P2formatNumber(0.10,’N2′)10.00%
0.10P3formatNumber(0.10’N3′)10.000%

Follow the example below:

1. Add the below-placed percentage expression in the ‘Value’ parameter of an initialized variable.

formatNumber(triggerBody()['number'],'P1')
Power Automate format number to percentage

2. The returns of the formatNumber expression will be displayed in the outputs of compose.

Power Automate format number to percentage expression

This way, we can format numbers into percentages in Power Automate.

How to Format Number to Hexadecimal in Power Automate

The hexadecimal format is the number system with a base value of ‘16‘, which includes numbers from (0-9) and digits from (A-F).

Examples:  7B316, 6F16.

In Power Automate, this format can be achieved using the formatNumber() expression with the standard format of ‘X‘. This format only works for the whole numbers.

Follow the below instructions:

1. In the ‘Initialize variable’ change the expression of formatNumber to hexadecimal format. Use the below expression placed in the code.

formatNumber(triggerBody()['number'],'X')
Power Automate format number to Hexadecimal expression

2. The hexadecimal format of the provided number will be displayed in the below screenshot.

Power Automate format number to Hexadecimal

This way, we can format a number to hexadecimal in Power Automate.

Power Automate Fixed Point Decimal Places

Regardless of how many decimal places the provided number has, the formatted number will be presented in the Fixed-Point decimal places corresponding to the decimal we fixed in the formatNumber() expression.

If the provided number is a whole number, it will be added to that number by a fixed number of decimal places.

This can be done using the standard ‘F‘ format in the formatNumber() expression. The precision specifier will define the number of decimal places that should be displayed.

NumberFormatExpressionResult
56789FformatNumber(56789,’F’)56789.00
56789F0formatNumber(56789,’F0′)56789
56789F1formatNumber(56789,’F1′)56789.0
56789F2formatNumber(56789,’F2′)56789.00
89.145263F3formatNumber(56789,’F3′)89.145

1. Add the ‘Initialize variable’ flow action and set the below details.

  • Name: Enter a name for a variable.
  • Type: Select a datatype from the drop-down.
  • Value: Add the value as given in the code below.
formatNumber(triggerBody()['number'],'F3')
Power Automate format number to Fixed point decimal expression

2. The compose flow action outputs will give the return value from the formatted number expression.

Power Automate format number to Fixed point decimal

How to Format Number as Exponent in Power Automate

Power Automate has a formatNumber() function that converts numbers into exponent form using the standard ‘E‘ format.

The exponential format is in the form of (E+n). There is always a dot after one digit. In the expression, ‘E’ followed by the number will define how many digits should be displayed after the dot. By default, it will take six digits after the dot.

NumberFormatExpressionResult
596EformatNumber(596,’E’)5.960000E+002
596E1formatNumber(596,’E1’)6.0E+002
596E2formatNumber(596,’E2’)5.96E+002
596E3formatNumber(596,’E3’)5.960E+002

1. Add the value of the initializing variable with the formatNumber expression that will convert the number into an exponential format.

Value: formatNumber(triggerBody()['number'],'E')
Power Automate formatNumber to exponent format

2. The outputs of the compose data operation will display the formatted number in exponential format, as shown below.

Power Automate format number expression exponential

This way, we can format a number as an exponent in Power Automate.

Conclusion

I hope this article gave you an overall idea of how to work with format numbers in Power Automate. There are various examples, such as format number as currency in Power Automate, format number to leading zeros in Power Automate, and many more.

Some more articles you may also like: