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

Question:

by Anonymous Monk
on Nov 07, 2001 at 02:33 UTC ( #123711=note: print w/replies, xml ) Need Help??


in reply to Using (s)printf()

say you have:
$half = 1/2;
and you want to print $half so it appears as:
.500

printf ("%.3f", $half);
gives:
0.500
how do i get rid of that extra zero?

Replies are listed 'Best First'.
Re: Question:
by Anonymous Monk on Mar 13, 2002 at 20:50 UTC
    Use split() to get rid of it.
      sub _round {
      my $digits = shift;
      my $num = shift;

      my $add = 5 * (10 ** -($digits + 1));

      $num += $add;

      my ($int,$frac) = split /\./,$num;

      $frac = substr($frac, 0, $digits);

      $num = join '.', $int, $frac;

      return $num;
      }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://123711]
help
Chatterbox?
[marto]: did that pg-GPU engine ever go mainstream?
[erix]: pgstrom? no, I don't think so
[erix]: although I have to admit its project page looks reasonable uptodate

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2018-05-24 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?