XP is just a number | |
PerlMonks |
Re: Zero Padding to the Right of the Decimalby davido (Cardinal) |
on Jan 15, 2004 at 16:17 UTC ( [id://321597]=note: print w/replies, xml ) | Need Help?? |
You just have the order of things mixed up a little.
Here's what you have:
So you turn $i into a string with padding, and then you increment by 0.01, which causes Perl to coerce the string into a number. At that point, string formatting is lost, and you get Perl's default numeric formatting. You could correct the problem by eliminating the sprintf and turning your print into printf, or simply increment $i before the sprintf statement instead of after, so that the effect sprintf has of coercing a value into a string isn't lost prior to the print. Smile! Most languages don't even let you coerce strings into numeric values, and back again, without using two different variables and a conversion function. Perl does its best at Doing What You Mean. Hope this helps.
Dave
In Section
Seekers of Perl Wisdom
|
|