在CGI脚本中仅将值打印到两位小数

时间:2015-12-10 02:32:09

标签: cgi

print <<here;
<div align="center">
<h2>Grades</h2>
<table border ="2" bordercolor="green">
  <tr>
    <td>Name</td><td>Id#</td><td>Test 1</td><td>Test 2</td><td>Test 3</td><td>Average</td>
  </tr>
here

my @record = $sql->fetchrow_array;  ### there is only one row in resultset

for(my $i = 0; $i < @record; $i++ ) {
  print "<td>$record[$i]</td>";
}
"<td>$avg \%.2f</td>";
print "</tr>";
print "</table></div></body></html>";

我无法将$avg打印到只有两位小数。

1 个答案:

答案 0 :(得分:0)

使用printf()使用特定格式打印数字:

printf("<td>%0.2f</td>\n", $avg);