Untuk memaparkan dua tempat perpuluhan, gunakan number_format(). Mari mulakan dengan menulis kod PHP yang sama. Kami mula-mula mengisytiharkan dua pembolehubah untuk dimulakan-
$number1=10.3423; $number2=10;
Sekarang, gunakan fungsi number_format() untuk memaparkan dua perpuluhan-
$result1=number_format ($number1, 2); $result2=number_format ($number2, 2);
The berikut ialah Contoh −
<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>
Berikut ialah petikan kod PHP−
10.34 10.00
Atas ialah kandungan terperinci Bagaimana untuk memaparkan dua tempat perpuluhan dalam MySQL/PHP?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!