Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Deleting trailing 0's after using sprintf

by jweed (Chaplain)
on Mar 19, 2004 at 06:39 UTC ( [id://337906]=note: print w/replies, xml ) Need Help??


in reply to Deleting trailing 0's after using sprintf

This is actually an exercise in Jeff Friedl's Mastering Regular Expressions.
His final reccomendation is to skip the sprintf alltogether and just use
$percent_change =~ s/(\.\d\d(?>[1-9]?))\d+/$1/
Which always keeps 2 digits, i.e. 2.500 => 2.50.
If you don't wan that to happen, use
$percent_change =~ s/(\.\d(?>[1-9]{0,2}))\d+/$1/



Code is (almost) always untested.
http://www.justicepoetic.net/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-25 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found