Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Rounding with sprintf and -0

by Khen1950fx (Canon)
on Apr 07, 2013 at 06:55 UTC ( #1027330=note: print w/ replies, xml ) Need Help??


in reply to Rounding with sprintf and -0

Since you just want an unsigned 0, use %u and String::Sprintf:

#!/usr/bin/perl -l use strict; use warnings; use String::Sprintf; my $formatter = String::Sprintf->formatter( F => sub { my($width, $value, $values, $letter) = @_; my $s = sprintf "%${'width'}f", $value; $s =~ s/\.?0*$//; return $s; } ); print $formatter->sprintf( "%u", -0.5 );


Comment on Re: Rounding with sprintf and -0
Select or Download Code
Re^2: Rounding with sprintf and -0
by Anonymous Monk on Apr 07, 2013 at 07:17 UTC

    and String::Sprintf:

    No Khen1950fx , even sprintf has %u, not that you need to sprintf twice

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2015-07-03 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls