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 );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Rounding with sprintf and -0
by Anonymous Monk on Apr 07, 2013 at 07:17 UTC |
In Section
Seekers of Perl Wisdom