2

我需要在表数组输出中舍入 SQL 舍入的结果。我无法弄清楚语法...

$result = mysql_query("SELECT `Energ_Kcal`*`yield`*`qty` AS `cal` FROM allinnot a
WHERE `own_id` = $user->id");

    echo "<tr><td>" . $row['Shrt_Desc'] . "</td><td>&nbsp;" . $row['desc'] . "</td><td>" . $row['cal'] . " cal</td></tr>";

cal返回一个包含许多小数点后数字的值。我只需要它来显示一个整数。我试过 ROUND(),但我一定是把它放错了地方。

4

3 回答 3

3

一般语法

ROUND( expression, 2 )
于 2012-04-09T19:31:53.573 回答
2

ROUND 应该绕过这些值,试试这个:

$result = mysql_query("SELECT ROUND(`Energ_Kcal`*`yield`*`qty`,2) AS `cal` FROM allinnot a
WHERE `own_id` = $user->id");

    echo "<tr><td>" . $row['Shrt_Desc'] . "</td><td>&nbsp;" . $row['desc'] . "</td><td>" . $row['cal'] . " cal</td></tr>";
于 2012-04-09T19:31:45.653 回答
0

您还可以查看 PHP 的round(),或者可能从您的描述中查看int_val()

于 2012-04-09T19:31:46.957 回答