Hi.. I've run into a bit of whackiness that I'm at a loss to explain, I've tried this on 3 different machines (all running some flavor of linux), and the behaviour repeats. Perhaps I'm incorrect in my use of printf, but I've found nothing indicating this..
I'm attempting to round a number to 2 decimal places:
my (@numbers) = qw( 0.256 0.255 0.254 );
printf("%0.2f\n", $_) foreach @numbers;
printf("%0.2f\n", 1.255);
I'd expect results like:
0.26
0.26
0.25
1.26
But what I'm seeing are results like:
0.26
0.26
0.25
1.25
Notice the 1.2
5 vs 1.26 that I'd expect..
As I said, I'm confused.. feel free to smite me down if I've pulled some kind of noob mistake.
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.