PHP numeric formatting

Source: Internet
Author: User

For example, echo number_format (285266237 );

Output 285,266,237

In addition, if you need to format the file size in bytes, the following methods can be used for reference:

Function byte_format ($ input, $ dec = 0)
{
$ Prefix_arr = array ('B', 'k', 'M', 'G', 'T ');
$ Value = round ($ input, $ dec );
$ I = 0;
While ($ value> 1024)
{
$ Value/= 1024;
$ I ++;
}
$ Return_str = round ($ value, $ dec). $ prefix_arr [$ I];
Return $ return_str;
}

Response byte_format (285266237 );
The result is 272 MB.

For example, echo number_format (285266237 );
Output 285,266,237
In addition, if you need to format the file size in bytes, the following methods can be used for reference:
Function byte_format ($ input, $ dec = 0)
{
$ Prefix_arr = array ('B', 'k', 'M', 'G', 'T ');
$ Value = round ($ input, $ dec );
$ I = 0;
While ($ value> 1024)
{
$ Value/= 1024;
$ I ++;
}
$ Return_str = round ($ value, $ dec). $ prefix_arr [$ I];
Return $ return_str;
}

Echo byte_format

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.