Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by FunkyMonk (Chancellor)
on Dec 11, 2007 at 23:42 UTC ( [id://656515]=note: print w/replies, xml ) Need Help??


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

printf a sprintf'ed number:
for ( -0.1, -0.01, -0.001, -0.0001, -10 ) { printf "%s --> %0.1f\n", $_, sprintf "%0.1f", $_ }

Replies are listed 'Best First'.
Re^2: Negative zero? There's gotta be a sprintf that undoes that, right?
by duckyd (Hermit) on Dec 12, 2007 at 02:30 UTC
    This doesn't work for me, perl 5.8.6 on OS X, however with a little change it does:
    for ( -0.1, -0.01, -0.001, -0.0001, -0.00001, -10, ) { my $num = sprintf "%0.1f", $_; $num = abs( $num ) if $num == 0; printf "%s --> %0.1f\n", $_, $num; }

Log In?
Username:
Password:

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

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

    No recent polls found