Home > Backend Development > PHP Tutorial > Summary of methods for rounding in PHP_PHP tutorial

Summary of methods for rounding in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:05:03
Original
810 people have browsed it

A summary of the methods of rounding in PHP

This article mainly introduces the methods of rounding in PHP. The examples summarize the three common methods of rounding in PHP, which has certain reference value. , friends in need can refer to it

The example in this article summarizes the method of rounding in PHP. Share it with everyone for your reference. The specific analysis is as follows:

Three ways to implement rounding in PHP, using the number_format function, round function and sprintf formatted output method to achieve rounding

1.number_format method implements rounding

?

1

2

3

4

5

$number = 1234.5678;

$nombre_format_francais = number_format($number, 2, ',', ' ');

// 1 234,57

$english_format_number = number_format($number, 2, '.', '');

// 1234.57

1 2

3

4

5

1

2

3

$number = 1234.5678;

echo round($number ,2);

//1234.57

$number = 1234.5678; $nombre_format_francais = number_format($number, 2, ',', ' ');

// 1 234,57

$english_format_number = number_format($number, 2, '.', '');

// 1234.57

1

2

3

$formatted = sprintf ("%s有¥%01.2f。",$name, $money);

echo $formatted;

//张三有¥123.10。

2.round method to achieve rounding

?

12 3
$number = 1234.5678; echo round($number ,2); //1234.57
3.sprintf formatted input to achieve rounding ?
1 2 3 $formatted = sprintf ("%s has ¥%01.2f.",$name, $money); echo $formatted; //Zhang Sanyou¥123.10.
I hope this article will be helpful to everyone’s PHP programming design. http://www.bkjia.com/PHPjc/964000.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/964000.htmlTechArticle Summary of the method of rounding in php This article mainly introduces the method of rounding in php, and the example summarizes the rounding in php Three commonly used methods have certain reference value...
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