> perl -e 'print sprintf("%.0f%", 1/30*100)'
3%
Update: Aside from sprintf formatting, if what you're really trying to do is compare two floating point numbers for Test::More, you might want to look at Test::Number::Delta, which I wrote to avoid that kind of roundabout way of comparing numbers. E.g.
use Test::More tests => 1;
use Test::Number::Delta within => .01;
my $percent = 1/30;
delta_ok( $percent, 0.03, 'values within 1%');
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|