Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Negative zero? There's gotta be a sprintf that undoes that, right?

by suaveant (Parson)
on Dec 12, 2007 at 15:13 UTC ( [id://656649]=note: print w/replies, xml ) Need Help??


in reply to Re: Negative zero? There's gotta be a sprintf that undoes that, right?
in thread Negative zero? There's gotta be a sprintf that undoes that, right?

Now... here's a really sick method that uses the regexp, but only to remove the leading - when needed. -0 == 0 but also -0 lt 0 so...
$num=sprintf("%7.5f",$num); $num=~s/^-// if $num == 0 && $num lt 0;
minimal regexp work and works for any precision.

Update Caveat... only works in locales where "-" is lower than 0-9

                - Ant
                - Some of my best work - (1 2 3)

  • Comment on Re^2: Negative zero? There's gotta be a sprintf that undoes that, right?
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2024-04-26 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found