Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Floats with trailing zeros as a hash key

by kilinrax (Deacon)
on May 09, 2003 at 14:57 UTC ( [id://256891]=note: print w/replies, xml ) Need Help??


in reply to Floats with trailing zeros as a hash key

Use printf rather than print to output the hash keys.
printf "%.2f\n", $_ for keys %ITEMS; __OUTPUT__ 58.29 38.55 45.20 29.95

Replies are listed 'Best First'.
Re: Re: Floats with trailing zeros as a hash key
by hardburn (Abbot) on May 09, 2003 at 14:59 UTC

    The prints I had in the example were only that: an example. The real script is accessing the hash based on some user input (with validation, of course), not printing out all the keys just for fun.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    Note: All code is untested, unless otherwise stated

      Then use sprintf? The internal representation of numbers shouldn't really matter - you can always convert them to the right format if needs be.

      If it is important, then initialise them all as strings for consistency, at least.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://256891]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 10:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found