• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

Insert 0 before number?

Hey

Powershell

I have some variables for example:

$a = 1242
$b = 12342

I need to return: (always 8 digits)

00001242
00012321

Mike
0
mikeydk
Asked:
mikeydk
1 Solution
 
oBdACommented:
Either with the ToString() method:
$a.ToString('D8')

Open in new window

Or with the format operator "-f" (better if you want to add some other output anyway):
"Current value of `$a: {0:D8}" -f $a

Open in new window

1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Live Q & A: Securing Your Wi-Fi for Summer Travel

Traveling this summer? Join us on June 18, 2018 for a live stream to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now