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

checking that numbers are in required format before using them

Hi,
I have a script that does some string concatenation that includes numbers that get pulled from various places. Before I can use them, however, I need all the numbers to be in a consistent  format (usually, ###) so that they sort properly.

How do you write an IF statement that checks adds leading zeros as needed so that 1,10,100 become 001,010,100?

Thanks in advance.



0
Leprechaun
Asked:
Leprechaun
1 Solution
 
lwadwellCommented:
Hi Leprechaun,

I would use a sprintf ... e.g.

$x = sprintf "%03d", $y;

In fact, you probably could use the sprintf to do all of your concatentation.

lwadwell
0
 
LeprechaunAuthor Commented:
Great, thank you.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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