Home  >  Article  >  Backend Development  >  Usage of PHP number formatting function number_format

Usage of PHP number formatting function number_format

WBOY
WBOYOriginal
2016-07-25 08:55:311187browse
  1. number_format(288);
  2. Output 288
  3. number_format(365,2);
  4. Output 365.00
  5. number_format(365000000,3,".") (retain the number 365000000 with 3 decimal places, small Use " for counting points". " means)
  6. Output: 365,000,000.000
  7. number_format(365000000,2,".","*") (retain the number 365000000 to 2 decimal places, the decimal point is represented by ".", and the thousand separator is represented by "*")
  8. Output: 365*000*000.00
Copy the code

Attached, an example of php intercepting the number of decimal places:

  1. // number_format method

  2. $number_format $number = 1234.5678;
  3. $nombre_format_francais = number_format($number, 2, ',', ' '); // 1 234 ,57
  4. $english_format_number = number_format($number, 2, '.', ''); // 1234.57
  5. // round method bbs.it-home.org
  6. round $number = 1234.5678; echo round($number ,2 ); //1234.57
  7. // sprintf method
  8. sprintf $formatted = sprintf ("%s has ¥%01.2f.", $name, $money); echo $formatted; //Zhang San has ¥123.10.
  9. ?>

Copy code


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