Home>Article>Backend Development> How to achieve division with two decimal places in PHP
php method to implement division with two decimal places: 1. Use the "/" operator to perform division operation, the syntax is "value 1 / value 2"; 2. Use "number_format (result of division operation, 2 )" or "sprintf("%.2f", the result of division operation)" statement to retain two decimal places.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php realizes division and retains two digits Decimals can be divided into two parts:
使用number_format()保留两位小数:".number_format($c, 2); echo "Recommended learning: "
使用sprintf()保留两位小数:".sprintf("%.2f",$c); ?>
PHP Video Tutorial》
The above is the detailed content of How to achieve division with two decimal places in PHP. For more information, please follow other related articles on the PHP Chinese website!