PHPround () function rounding php function-PHP source code

Source: Internet
Author: User
The PHPround () function rounds the php function. In php, the round () function is used to round the floating point number. The round (x, prec) PHP round () function is rounded to the php function. In php, the round () function is used to round the floating point number. Round (x, prec)

Script ec (2); script

X is the floating point data to be processed.
Prec, save a few decimal places
Tips and comments
Note: PHP cannot properly process strings similar to "12,300.2" by default.

Note: The prec parameter is introduced in PHP 4 ..

*/

// The Truncation function of the Instance floating point number. The return value is still a floating point number.


$ Foo = round (3.4); // $ foo = 3.0
$ Foo = round (3.5); // $ foo = 4.0
$ Foo = round (3.6); // $ foo = 4.0
$ Foo = round (3.6, 0); // equivalent with above

$ Foo = round (1.95583, 2); // $ foo = 1.96

$ Foo = round (1241757,-3); // $ foo = 1242000

// Round instance 2

Echo (roround (0.68 ));
Echo (roround (0.40 ));
Echo (roround (0.3 ));
Echo (round (-3.30 ));
Echo (round (-4.90 ));

/*

1
0
0
-3
-5
*/
// Returns the result of rounding x to the specified precision prec (number of digits after decimal point. Prec can also be a negative number or zero (Default 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.