Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Eliminating Trailing Zeros

by jmcnamara (Monsignor)
on Jul 17, 2003 at 15:18 UTC ( [id://275243]=note: print w/replies, xml ) Need Help??


in reply to Eliminating Trailing Zeros


Use the g format instead of f and no further formatting should be required:
$ perl -e 'printf "%2.4g\n", 23.05' 23.05 $ perl -e 'printf "%2.4g\n", 23.00' 23
See the sprintf manpage for more details:
g The double argument is converted in style f or e (or E for G conversions). ... Trailing zeros are removed from the fractional part of the result; ...

--
John.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 13:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found