Formatting a Variable

M

Mike

Hi,

I need to check that a number entered fits a specific format, and if
it doesn't, then I need to modify that variable to fit the format. For
instance, I need for the user to enter a number like 0123456.7
(specifically needing 7 numbers, followed by a . and another number).

The FORMAT function doesn't do what I thought. In Java (as much as I
hate Java), Format would do this in one line. Is there a command that
I'm overlooking in Perl that would do this for me?

TIA,

Mike
 
A

Anno Siegel

Mike said:
Hi,

I need to check that a number entered fits a specific format, and if
it doesn't, then I need to modify that variable to fit the format. For
instance, I need for the user to enter a number like 0123456.7
(specifically needing 7 numbers, followed by a . and another number).
^^^^^^^ ^^^^^^
"digit(s)"
The FORMAT function doesn't do what I thought. In Java (as much as I
hate Java), Format would do this in one line. Is there a command that
I'm overlooking in Perl that would do this for me?

my $formatted = sprintf "%09.1f", $number;

See perldoc -f sprintf.

Anno
 
M

Mike

my $formatted = sprintf "%09.1f", $number;


Geez, man, what's wrong with me? That's Perl 101. Can I chalk that one
up to late-night brain-fried?

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top