cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Eyerise
Level: Powered On

Add Leading Zero's on Number Input

I'm wondering if someone has come across a solution to adding leading zeros to a number. 
The idea is that I have an identifying number that is always 5 digits so the output I would like to see is:

  • 00001 (original number 1)
  • 00022 (original number 22)
  • 00333 (original number 333)
  • 04444 (original number 4444)

I can add leading zeros no problem with concat so if I add four zeros to the start (0000) the output I get is

  • 00001
  • 000022
  • 0000333
  • 00004444

How can I extract the substring from the right to a lenght of 5?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Add Leading Zero's on Number Input

@Eyerise:

 

Here is a Flow that runs successfully that I believe demonstrates what you are trying to accomplish.

 

Here is the formula that I am using for varLength:  

length(variables('varStart'))

 

Here is the expression that I'm using for varResult:

substring(variables('varStart'),sub(variables('varLength'),5),5)

 

This solution should work regardless of how long you make the initial string.

 

RightString1.jpgRightString2.jpgRightString3.jpg   

 

If this addresses your issue, please mark you post as Solved.

 

Scott

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Add Leading Zero's on Number Input

@Eyerise:

 

Here is a Flow that runs successfully that I believe demonstrates what you are trying to accomplish.

 

Here is the formula that I am using for varLength:  

length(variables('varStart'))

 

Here is the expression that I'm using for varResult:

substring(variables('varStart'),sub(variables('varLength'),5),5)

 

This solution should work regardless of how long you make the initial string.

 

RightString1.jpgRightString2.jpgRightString3.jpg   

 

If this addresses your issue, please mark you post as Solved.

 

Scott

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott

View solution in original post

wdenny
Level: Powered On

Re: Add Leading Zero's on Number Input

A couple quick thoughts...

 

Are you actually usings strings? I ask since you are using concat to pad zero's to the left.

 

One idea would be to only pad on the number of zero's you need?  You could do this by getting the lenght of the current string, then only concat w/ the number of zero's required.  That would negate the need for your question.

 

However, to answer your actual ask, could you not use the lenght of the string minus 5 for the "start" parameter of substring, and then you would get the last 5?  Too bad there isn't a left() or right() parallel in flow just yet.

 

Eyerise
Level: Powered On

Re: Add Leading Zero's on Number Input

@ScottShearer 

Thank you for the quick reply. I gave it a go and its working perfectly. Appreciate the help!!

Eyerise
Level: Powered On

Re: Add Leading Zero's on Number Input

@wdenny 

Thanks for the repy! Interesting idea to find the length and then add the appropriate number of zeros. Would have been my backup plan if I couldn't get it done a more traditional way.

 

If anyone else is reading along I added a Uservoice to see if Left() and Right() can be added to the expressions list.

Have the expressions for Left() and Right()

wdenny
Level: Powered On

Re: Add Leading Zero's on Number Input

Hey, in my world, if it aint broke, don't recode it! Thanks for reading it anyway!

 

I voted your left/right UV up as that would be nice, and surely isn't a huge stretch for them functionally.

 

Flow On!

Highlighted
VincentVH
Level: Powered On

Re: Add Leading Zero's on Number Input

I agree: either a right(TEXT,LENGTH)-function or the option to make the second parameter to substring() negative would be so much more elegant.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 250 members 5,972 guests
Please welcome our newest community members: