Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: sprintf percent formatting

by b10m (Vicar)
on Aug 17, 2005 at 12:50 UTC ( [id://484405]=note: print w/replies, xml ) Need Help??


in reply to sprintf percent formatting

sprintf is probably what you want, yet give it a slightly altered input and it'll work:

use strict; use warnings; use Test::More qw(no_plan); my $percent = sprintf("%d%%",(1/3)*100); is($percent,"33%"); print "Result: $percent\n"; $percent = sprintf("%d%%",(1/30)*100); is($percent,"3%"); print "Result: $percent\n";

Instead of '%02d%%', I now use '%d%%' which seems to be what you want.

--
b10m

All code is usually tested, but rarely trusted.

Log In?
Username:
Password:

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

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

    No recent polls found