Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: sprintf percent formatting

by b10m (Vicar)
on Aug 17, 2005 at 12:50 UTC ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-01-28 07:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?