How to Format Numbers with Leading Zeros in Power Automate?

Are you stuck on adding leading zeros? I will show you how to add leading zeros to a Number using Power Automate. Using various approaches and examples, I will show you how to format numbers with leading zeros in Power Automate.

Here, I will show you two approaches to add leading zero to a number using flow. In the first approach, we will use the Format Number action to add a leading zero.

In the second approach, we will use the Format Number function to add a leading zero to the numbers in the Power Automate flow.

We will also cover how to Add Leading Zeros to Text with the substring Function in Power Automate.

Now in the following, we will see, how to Format Numbers with Leading Zeros using Power Automate flow.

What are leading zeros?

  • The leading zero is added only to the first nonzero digit in a number. Also maintains the fixed width for the numerical values.
  • In some cases, we are in a need to pad zero values to the numbers. For example, while working on code generation, serial numbers, or other unique identifiers. we have to make sure that the generating code has a fixed number of digits for consistency. In those cases, we can add the leading zero values.

How to Format Numbers with Leading Zeros using Power Automate flow

Let us see how to Format Numbers with Leading Zeros using Power Automate flow.

Approach -1: (Format Number action)

In the first approach, we will Format Numbers with Leading Zeros using the Format Number action.

Step-1:

Create an instant cloud flow and expand the trigger action. Then, add a number input which is of number data type as shown below:

power automate format number with leading zeros

Step-2:

From the action triggers, select the Format Number action. Provide the required parameters.

  • Number – Pass the dynamic content of the number input
  • Format – Choose the Custom value as an option and enter the value as 000000 as displayed below:
triggerBody()['number']
power automate format number with leading zeros using Format Number action

Step-3:

Save and Run the flow. Enter the number input and choose the run flow option.

How to format number with leading zeros in Power Automate flow

Once the flow runs successfully, we can see the leading zero has been added to the input number and displayed the output as 001234.

add leading zeros to numbers in power automate flow

This is how to Format Numbers with Leading Zeros using Format Number action in Power Automate flow.

Approach-2:(Format Number function)

In the Second approach, we will Format Numbers with Leading Zeros using the Format Number Function.

Syntax of Format Number function:

formatNumber(number : number, format: string, locale?: string)

Where,

  • format-number – function name
  • number – input number (required field)
  • format – format that should be applied to format the number (required field)
  • locale? – a locale that is used to format the number (optional field)

Step-1:

Create an instant cloud flow and expand the trigger action. Then, add a number input with a number data type as shown below:

power automate format number with leading zeros

Step-2:

Add a compose data operation, and pass the below expression to add leading zeros under the expression tab.

formatNumber(triggerBody()['number'],'000000')

Where,

  • format-number – function name
  • number – input value
power automate format number with leading zeros using Format Number function

Step-3:

Save and Run the flow. Enter the number input and choose the run flow option.

Format number with leading zeros in Power Automate

Once the flow runs successfully, we can see the leading zero has been added to the input number and displayed the output as 063245.

How to format number with leading zeros in Power Automate

This is how to Format Numbers with Leading Zeros using the Format Number function in Power Automate flow.

How to Add Leading Zeros to Text with the Substring Function in Power Automate

Let us see how to add leading zeros to text with the Substring Function in Power Automate flow,

Step-1:

Create an instant cloud flow and expand the trigger action. Then, add a number input with a text data type as shown below:

How to Add Leading Zeros to Text with the Substring Function in Power Automate flow

Step-2:

Add a compose data operation, and pass the below expression to add leading zeros under the expression tab.

substring(concat('00000000',triggerBody()['text']),sub(add(8,length(triggerBody()['text'])),6),6)
How to Add Leading Zeros to Text with the Substring Function in Power Automate

Step-3:

Save and Run the flow. Enter the number input and choose the run flow option.

Add Leading Zeros to Text with the Substring Function in Power Automatef flow

Once the flow runs successfully, we can see the leading zero has been added to the text number input and displayed the output as 000235.

Add Leading Zeros to Text with the Substring Function in Power Automate

This is how to add leading zeros to text with the Substring Function in Power Automate flow.

Conclusion

I hope you know how to Format Numbers with Leading Zeros using Power Automate flow. Here, I have done two examples; in the first example, I added leading zeros using the Format Number action.

In the other example, I added leading zeros using the Format Number function. I also showed you how to add leading zeros to text with the Substring Function in Power Automate flow.

You may also like:

>