A small example of formatting numbers in PHP. Example of how to use the number_format function.

WBOY
Release: 2016-07-25 08:57:38
Original
1361 people have browsed it
  1. print number_format(100000.56);
  2. ?>
Copy code

Example 2, number_format($n, $p, $t, $d) rounds $n to $ p decimal places, using $t as the thousands separator and $d as the decimal separator.

  1. echo "Total charge is ", number_format($total, 2, ".", ","), " Euros";
  2. ?>
Copy code

Example 3. The number_format function is used in English format and Italian format

  1. $a = 1232322210.44;

  2. echo number_format ($a, 2); // English format
  3. echo "n";
  4. echo number_format ($a, 2, ',', '.'); // Italian format
  5. echo "n";
  6. ?>

Copy code

Example 4, output formatted number form

  1. print "The population of the US is about:";
  2. print number_format(285266237);
  3. ?>
Copy code


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