PHP: Number Format Function to Format Numbers in PHP (Integer or Float)

To display numbers to end users, especially large numbers, you may need to format them to be more user friendly. For example, with a large integer 43386000.75, it is usually preferred to comma-separate every 3 digits to this:

43,386,000.75

To format numbers this way in PHP, you need number_format() function:

print number_format(43386000.75); // prints '43,386,000.75'

This is English notation of numbers with thousands separator. For French number notation:

print number_format(43386000, 2, ',', ' '); // prints '43 386 000,75'

Deducing from the parameters used in the above example, we have the number_format() function synopsis:

string number_format ( float $number , int $decimals , string $dec_point , string $thousands_sep )

With number_format(), you can format any integer number of floating point number by thousands separator (which in most cases is a comma), decimal point (which usually is a period point), number of decimal digits after the decimal point.

4 thoughts on “PHP: Number Format Function to Format Numbers in PHP (Integer or Float)”

  1. how to make 0001 from 1 ? or from 94 to 0094 ? or like from 35.6 going tobe 0035.6 ?

    $a=1;
    $b=4;//4 digit max

    ive my own function to create it, but some says its already build in php fucntion, what it is name?

  2. Dear sir / madam

    I have need to convert number to words in php.

    Like 123 to convert in word please sent me the ans.

Comments are closed.

Scroll to Top