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() - ����ָ����ʽ����������ַ�