Number_format in PHP

Source: Internet
Author: User

Number_format - format a number in thousands separators

String number_format ( float $number [, int $decimals = 0 ])

String Number_format(Float $number, int $decimals = 0 , string $dec_point = "." , string $thousands_sep = "," )

This function can accept 1, 2, or 4 parameters (Note: cannot be 3):

If only the first argument is provided, number the decimal section is removed and each thousand separator is the English lowercase comma ","

If you provide two parameters, the number number of digits after the decimal point will be retained to the value you set, the rest of the same upstairs

If four parameters are supplied, the fractional number part of the length is retained, the decimals decimal point is replaced dec_point with the thousand separator is thousands_sep replaced by the

number

The number you want to format

decimals

The number of decimal digits to keep

dec_point

Specify the characters for the decimal point display

thousands_sep

Specify the characters that the thousands separator displays

$price = 12032.2395; $price 1=12032.568; Print Number_format ($price); out:12,032--Four print Number_format ($price 1); out:12,033-Five into print number_format ($price, ' 2 '); out:12,032.24  Print Number_format ($price, ' 2 ', '. ', ', ');//12,032.24

Number_format in PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.