Perl_控制输出小数点位数_sprintf
例
my $var=123.454789;
$var=sprintf "%.2f",$var;
print $var."\n";
#123.45
例
my $var=123.455789;
$var=sprintf "%.2f",$var;
print $var."\n";
#123.46
默认四舍五入
例:
输出百分比:
my $var1=0.456789;
$var1=sprintf "%.4f",$var1; $var1*=100; print $var1."%\n"; #45.68%