PHP Implementation Rounding Method Summary _php tutorial

Source: Internet
Author: User

Summary of methods for rounding in PHP


This article mainly introduces the method of rounding the PHP implementation, the example summarizes the PHP implementation rounding three common methods, with a certain reference value, the need for friends can refer to the following

This paper summarizes the method of rounding PHP implementation. Share to everyone for your reference. The specific analysis is as follows:

PHP Implementation rounding three methods, respectively through the Number_format function, round function and sprintf formatted output method to achieve rounding

1.number_format Method for 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

2.round Method for rounding

?

1

2

3

$number = 1234.5678;

Echo Round ($number, 2);

1234.57

3.sprintf formatted input for rounding

?

1

2

3

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

Echo $formatted;

Zhang San has ¥123.10.

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/964000.html www.bkjia.com true http://www.bkjia.com/PHPjc/964000.html techarticle summary of the method of rounding in PHP this article mainly introduces the method of rounding PHP implementation, the example summarizes the PHP implementation of rounding three common methods, with a certain reference value ...

  • 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.