number_format

(PHP 4, PHP 5, PHP 7)

number_format锟斤拷千位锟街革拷锟斤拷锟斤拷式锟斤拷式锟斤拷一锟斤拷锟斤拷锟斤拷

说锟斤拷

number_format ( float $number [, int $decimals = 0 ] ) : string
number_format ( float $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($number2','' ');
// 1 234,56

$number 1234.5678;

// english notation without thousands separator
$english_format_number number_format($number2'.''');
// 1234.57

?>

锟斤拷锟斤拷锟斤拷志

锟芥本 说锟斤拷
7.2.0 number_format() 锟斤拷锟斤拷锟睫凤拷锟斤拷锟斤拷 -0锟斤拷之前锟斤拷锟杰凤拷锟斤拷 -0锟斤拷锟斤拷为 number 锟斤拷锟杰伙拷锟斤拷 -0.01锟斤拷

锟轿硷拷

  • money_format() - 锟斤拷锟斤拷锟街革拷式锟斤拷锟缴伙拷锟斤拷锟街凤拷锟斤拷
  • sprintf() - Return a formatted string
  • printf() - 锟斤拷锟斤拷锟绞斤拷锟斤拷址锟斤拷锟�
  • sscanf() - 锟斤拷锟斤拷指锟斤拷锟斤拷式锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷址锟�