I think i see the problem from readin the other posts. You appear to be printing to a webpage which is not recognizing the consecutive spaces (or, atleast, not displaying them). Just for the sake of
sprintf(), i should mention that , if the number before the
. in the
sprintf() format is positive, the number is right justified, and a negative number to the left of the
. left justifies the number. so ...
#!/usr/bin/perl -w
use strict; # every job should
my $number = 222.42;
printf("A: \$%10.2f\n",$number);
printf("B: \$%-10.2f\n",$number);
... would print ...
%shell > perl test.pl
A: $ 222.42
B: $222.42
If HTML : There are quite a few ways to do it, and i have even been known to use something like the following before printing. But, i am not a CGI programmer, so i am sure there are better ways.
sub html_space {
my $Rstring = shift;
$$Rstring =~ s/ / /g;
}
... and a test program ...
#!/usr/bin/perl -w
use strict; # every job should
my $number = 222.42;
$number = sprintf("\$%10.2f\n",$number);
&html_space(\$number);
print "A: $number\n";
sub html_space {
my $Rstring = shift;
$$Rstring =~ s/ / /g;
}
can't sleep clawns will eat me
-- MZSanford
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.