Php implementation rounding method summary _ PHP Tutorial

Source: Internet
Author: User
Summary of php implementation rounding. Summary of php implementation rounding methods this article mainly introduces php implementation rounding methods, examples summarizes three common methods for php implementation rounding, has a certain reference value php implementation rounding methods summary

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, see

This example summarizes the php rounding method. 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

?

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. implement rounding of the round method

?

1

2

3

$ Number = 1234.5678;

Echo round ($ number, 2 );

// 1234.57

3. sprintf format input implementation rounding

?

1

2

3

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

Echo $ formatted;

// Picture 3 has 123.10 RMB.

I hope this article will help you with php programming.

This article describes how to implement rounding in php. The example summarizes three common methods for implementing rounding in php, which has some 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.