Summary of php rounding methods

Source: Internet
Author: User
This article mainly introduces how to implement rounding in php. The example summarizes three common methods for implementing rounding in php, which has some reference value, for more information about php implementation, see the examples in this article. Share it with you for your reference. The specific analysis is as follows:

Php provides three rounding methods: number_format, round, and sprintf.

1. implement rounding of number_format

$ Number = 1234.5678; $ nombre_format_francais = number_format ($ number, 2, ','); // 1 234,57 $ english_format_number = number_format ($ number, 2 ,'. ', ''); // 1234.57

2. implement rounding of the round method

$ Number = 1234.5678; echo round ($ number, 2); // 1234.57

3. sprintf format input implementation rounding

$ Formatted = sprintf ("% s has ¥ % 01.2f. ", $ Name, $ money); echo $ formatted; // Picture 3 has $123.10.

I hope this article will help you with php programming.

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.