&l"/> &l">

Home  >  Article  >  Backend Development  >  Example code sharing of PHP retaining 2 decimal places

Example code sharing of PHP retaining 2 decimal places

零下一度
零下一度Original
2017-06-28 15:39:571686browse

JS retains two decimal places example to round using function toFixed()

PHP rounding to two decimal places example

< ;?php

/**1.number_format*/

$number = 1234.5678;

$nombre_format_francais = number_format($number, 2, ',', ' ' ); // 1234,57

$english_format_number = number_format($number, 2, '.', ''); // 1234.57 (I usually use this)

/**2.round*/

$number = 1234.5678;

echo round($number ,2); //1234.57

/**3.sprintf*/

$formatted = sprintf ("%s has ¥%01.2f.", $name, $money);

echo $formatted; // Zhang San has ¥123.10.

?>

The above is the detailed content of Example code sharing of PHP retaining 2 decimal places. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn