Example code sharing of PHP retaining 2 decimal places

零下一度
Release: 2023-03-10 17:36:02
Original
1734 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template