要显示两位小数,请使用 number_format()。让我们首先编写相同的 PHP 代码。我们首先声明两个变量被初始化 -
$number1=10.3423; $number2=10;
现在,使用number_format()函数显示两个小数 −
$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);
以下是示例 −
<span class="pun"><?</span><span class="pln">php</span> <span class="pln"> $number1</span><span class="pun">=</span><span class="lit">10.3423</span><span class="pun">;</span> <span class="pln"> $number2</span><span class="pun">=</span><span class="lit">10</span><span class="pun">;</span> <span class="pln"> $result1</span><span class="pun">=</span><span class="pln">number_format </span><span class="pun">(</span><span class="pln">$number1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span> <span class="pln"> $result2</span><span class="pun">=</span><span class="pln">number_format </span><span class="pun">(</span><span class="pln">$number2</span><span class="pun">,</span><span class="pln"> </span><span class="lit">2</span><span class="pun">);</span> <span class="pln"> echo </span><span class="pun">(</span><span class="pln">$result1</span><span class="pun">);</span> <span class="pln"> echo </span><span class="str">'<br>'</span><span class="pun">;</span> <span class="pln"> echo </span><span class="pun">(</span><span class="pln">$result2</span><span class="pun">);</span> <span class="pun">?></span>
以下是PHP代码的快照 −
10.34 10.00
以上是如何在MySQL/PHP中显示两位小数?的详细内容。更多信息请关注PHP中文网其他相关文章!