PHP Common mathematical Calculation intrinsics (mathematical Functions) _php tutorial

Source: Internet
Author: User
Tags floor function mathematical functions
This chapter describes several common PHP math intrinsic functions.

General calculations, we can solve by operators, such as subtraction. Using PHP's mathematical calculation intrinsics can help us solve some of the more complex calculations. The following mainly covers round, floor, ceil, pow, Rand,max, Min, Decbin, Bindec, Dechex, Hexdec, decoct, Octdec function.

Round
Round-Rounding the floating-point number. The round function syntax is as follows:

Round (float,precision)
Where the parameter precision represents the number of precision digits to be persisted after the decimal point. If the parameter precision is not written, it is rounded to the integer digits, for example:

Echo round (3.4); 3
Echo round (3.5); 4
Echo round (3.6); 4
If precision is 2, it is rounded to 2 digits after the decimal point. Examples are as follows:

Echo Round (1.95583, 2); 1.96
If the parameter precision is negative, it is rounded to the decimal point. Like what:

Echo Round (1241757,-3); 1242000
Floor
Floor-Rounding Method. The floor function syntax is as follows:

Floor (value)
The floor function returns the largest integer that is not greater than value, rounding out the fractional part of value. Examples are as follows:

Echo Floor (4); 4
echo floor (4.3); 4
echo Floor (9.999); 9
Ceil
Ceil-into a method to take the whole. The Ceil function syntax is as follows:

Ceil (value)
The Ceil function returns the smallest integer that is not less than value. Examples are as follows:

Echo Ceil (4); 4
echo ceil (4.3); 5
echo ceil (9.999); 10
Pow
Pow-exponentiation. The syntax for the POW function is as follows:

Pow (BASE,EXP)
The POW function returns the power of the exp sub-side of base. The following example shows a 2 8-time Square and returns a result of 256.

Echo Pow (2, 8); 256
Rand
Rand-produces a random integer. The RAND function syntax is as follows:

Rand (Min,max)
The RAND function returns a random integer between the min min and Max Max (including Min, Max). The following example returns a random integer from 2 to 6.

echo rand (2,6);
Max
Max-Returns the value that is the largest of the values in the parameter.

If the Max function has only one parameter and is an array, MAX returns the largest value in the array.

The Max function example is as follows:

echo Max (1, 3, 5, 6, 7); 7
echo Max (Array (2, 4, 5)); 5
Min
Min-Returns the minimum value in the parameter.

If the Min function has only one parameter and is an array, MIN returns the smallest value in the array.

The Min Function example is as follows:

Echo min (1, 3, 5, 6, 7); 1
echo min (Array (2, 4, 5)); 2
Decbin
Decbin-decimal is converted to binary. The Decbin function syntax is as follows:

Decbin (number)
Decbin returns a string that returns a binary representation of the number of the parameter. Examples are as follows:

Echo Decbin (12);
Decbin (12) The result of this return is:

1100
Bindec
BINDEC-binary converted to decimal. The BINDEC function syntax is as follows:

Bindec (binary_string)
The BINDEC function converts a binary string binary_string into a decimal integer. Examples are as follows:

echo bindec (' 110011 '); 51
Dechex, Hexdec
Dechex-Decimal conversion to 16 binary.

Hexdec-16 binary converted to decimal.

Dechex, an example of the HEXDEC function is as follows:

Echo Dechex (47); 2f
echo hexdec (' 2f '); 47
DECOCT, Octdec
DECOCT-Decimal conversion to octal

Octdec-Eight conversion to decimal

An example of the DECOCT,OCTDEC function is as follows:

Echo decoct (12); 14
Echo Octdec (' 14 '); 12

http://www.bkjia.com/PHPjc/477507.html www.bkjia.com true http://www.bkjia.com/PHPjc/477507.html techarticle This chapter describes several common PHP math intrinsic functions. General calculations, we can solve by operators, such as subtraction. Using PHP's mathematical calculation of intrinsic functions, you can ...

  • Related Article

    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.