Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: perl floating number addition

by Albannach (Prior)
on Jul 18, 2009 at 13:49 UTC ( #781324=note: print w/replies, xml ) Need Help??


in reply to Re: perl floating number addition
in thread perl floating number addition

A (pretty common) nit to pick here: the 3 in %3.2f is not the number of digits before the decimal, it's the minimum total width of the resulting field, including the decimal. So if you really want 3 digits, a decimal and 2 digits, then you need %6.2f. This is a minimum and the digits to the left of the decimal will still be printed, so your example of 895.3 still appears to work (even though it would be better described as %5.1f), but try that in a table and you'll find that the column won't line up when another value is just 1.23 for instance.

For illustration, printf("%3.2f\n",$_) for (3.2,32.2,322.2) gives:

3.20 32.20 322.20

while printf("%6.2f\n",$_) for (3.2,32.2,322.2) gives:

3.20 32.20 322.20

--
I'd like to be able to assign to an luser

Replies are listed 'Best First'.
Re^3: perl floating number addition
by biohisham (Priest) on Jul 18, 2009 at 14:12 UTC
    Thanks buddy for this, I will have it rectified, when I saw the start of your reply and I was like aoooo I mixed up some other coordinates system from another utility. Thanks, I admit I fell for the trap, I will make an update.
    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://781324]
help
Chatterbox?
[ambrus]: "you are far more likely to be squished between two other dudes" => wait, really? aren't most planes, weighted by people traveling on it, so narrow that there are only two or three seats on each side of the one corridor, so only one third of the people ge
[ambrus]: t squished between two other people?
holli is about to take the first hit since a month and this weed is strong shit. Should my head explode, someone call 911.
[ambrus]: And even when I traveled on a big plane for a long flight, it had 3 seats, then corridor, then 4 seats, then corridor, then 3 seats, so less than half of the people sit between two other dudes.
[1nickt]: you are missing an entire element, which is that your base ticket price only gets you a middle seat. If you want to be window or aisle you must pay, or gamble that you'll be assigned there at ...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-12-18 13:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (486 votes). Check out past polls.

    Notices?