Example of php number formatting (number_format function application)

WBOY
Release: 2016-07-25 09:00:31
Original
941 people have browsed it
PHP number formatting example (number_format function application), friends in need can refer to it.

For example,

echo number_format(285266237);
Copy after login

Output 285,266,237

If you need to use the number_format() function to format the file byte size, you can refer to the following method.

<?php
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(285266237);
?>
Copy after login

Output: 272M



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!