(PHP 4, PHP 5, PHP 7)
number_format — 锟斤拷千位锟街革拷锟斤拷锟斤拷式锟斤拷式锟斤拷一锟斤拷锟斤拷锟斤拷
$number
[, int $decimals
= 0
] ) : string$number
, int $decimals
= 0
, string $dec_point
= "."
, string $thousands_sep
= ","
) : string锟斤拷锟斤拷锟斤拷锟斤拷锟皆斤拷锟斤拷1锟斤拷锟斤拷2锟斤拷锟斤拷锟斤拷4锟斤拷锟斤拷锟斤拷锟斤拷注锟解:锟斤拷锟斤拷锟斤拷3锟斤拷锟斤拷:
锟斤拷锟街伙拷峁╋拷锟揭伙拷锟斤拷锟斤拷锟斤拷锟�number
锟斤拷小锟斤拷锟斤拷锟街会被去锟斤拷
锟斤拷锟斤拷每锟斤拷千位锟街革拷锟斤拷锟斤拷锟斤拷英锟斤拷小写锟斤拷锟斤拷","
锟斤拷锟斤拷峁╋拷锟斤拷锟斤拷锟斤拷锟斤拷锟�number
锟斤拷锟斤拷锟斤拷小锟斤拷锟斤拷锟斤拷位锟斤拷锟斤拷锟斤拷锟借定锟斤拷值锟斤拷锟斤拷锟斤拷同楼锟斤拷
锟斤拷锟斤拷峁╋拷锟斤拷母锟斤拷锟斤拷锟斤拷锟�number
锟斤拷锟斤拷锟斤拷decimals
锟斤拷锟斤拷锟饺碉拷小锟斤拷锟斤拷锟斤拷,
小锟斤拷锟姐被锟芥换为dec_point
锟斤拷千位锟街革拷锟斤拷锟芥换为thousands_sep
number
锟斤拷要锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷
decimals
要锟斤拷锟斤拷锟斤拷小锟斤拷位锟斤拷
dec_point
指锟斤拷小锟斤拷锟斤拷锟斤拷示锟斤拷锟街凤拷
thousands_sep
指锟斤拷千位锟街革拷锟斤拷锟斤拷示锟斤拷锟街凤拷
锟斤拷式锟斤拷锟皆猴拷锟� number
.
锟芥本 | 说锟斤拷 |
---|---|
5.4.0 |
This function now supports multiple bytes in
dec_point and
thousands_sep . Only the first byte of each
separator was used in older versions.
|
Example #1 number_format() Example
For instance, French notation usually use two decimals, comma (',') as decimal separator, and space (' ') as thousand separator. The following example demonstrates various way to format a number:
<?php
$number = 1234.56;
// english notation (default)
$english_format_number = number_format($number);
// 1,235
// French notation
$nombre_format_francais = number_format($number, 2, ',', ' ');
// 1 234,56
$number = 1234.5678;
// english notation without thousands separator
$english_format_number = number_format($number, 2, '.', '');
// 1234.57
?>
锟芥本 | 说锟斤拷 |
---|---|
7.2.0 |
number_format() 锟斤拷锟斤拷锟睫凤拷锟斤拷锟斤拷 -0锟斤拷之前锟斤拷锟杰凤拷锟斤拷 -0锟斤拷锟斤拷为 number 锟斤拷锟杰伙拷锟斤拷 -0.01锟斤拷
|