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:
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']
Step-3:
Save and Run the flow. Enter the number input and choose the run flow option.
Once the flow runs successfully, we can see the leading zero has been added to the input number and displayed the output as 001234.
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:
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
Step-3:
Save and Run the flow. Enter the number input and choose the run flow option.
Once the flow runs successfully, we can see the leading zero has been added to the input number and displayed the output as 063245.
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:
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)
Step-3:
Save and Run the flow. Enter the number input and choose the run flow option.
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.
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:
- How to format a number as currency in Power Automate?
- Power Automate formatdatetime
- Power Automate Number Format
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