PHP internal function learning

Source: Internet
Author: User
Tags binary to decimal decimal to binary floor function

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

Round (float, precision)
The precision parameter indicates the number of precision digits to be preserved after the decimal point. If the parameter precision is not specified, the number is rounded to an integer, for example:

Echo round (3.4); // 3 echo round (3.5); /// 4 echo round (3.6); // 4
If the precision is 2, it indicates rounding to the second digit after the decimal point. Example:

Echo round (1.95583, 2); // 1.96
If the precision parameter is negative, it indicates rounding to the decimal point. For example:

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

Floor (value)
The floor function returns the maximum integer not greater than the value, rounding out the decimal part of the value. Example:

Echo floor (4); // 4
Echo floor (4.3); // 4 echo floor (9.999); // 9
Ceil
Ceil-returns an integer from the first method. The ceil function syntax is as follows:

Ceil (value)
The ceil function returns the smallest integer not less than value. Example:

Echo ceil (4); // 4
Echo ceil (4.3); // 5 echo ceil (9.999); // 10
Pow
Pow-power. The syntax of the pow function is as follows:

Pow (base, exp)
The pow function returns the power of base exp. The following example calculates the power of 2 and returns 256.

Echo pow (2, 8); /// 256
Rand
Rand-generates a random integer. The rand function syntax is as follows:

Rand (min, max)
The rand function returns a random integer between min and max (including min and max. For example, the following example returns a random integer between 2 and 6.

Echo rand (2, 6 );
Max
Max-the maximum value of the returned parameter.

If the max function has only one parameter and is an array, max returns the maximum value of this 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-return 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.

Min function example:

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

Decbin (number)
Decbin returns a string, that is, the binary representation of the parameter number. Example:

Echo decbin (12 );
DE> decbin (12) DE> the returned result is:

1100
Bindec
Bindec-convert binary to decimal. The bindec function syntax is as follows:

Bindec (binary_string)
The bindec function converts the binary string binary_string into a decimal integer. Example:

Echo bindec ('123'); // 51
Dechex, hexdec
Dechex-decimal to hexadecimal.

Convert hexdec-hexadecimal to decimal.

Example of the dechex and hexdec functions:

Echo dechex (47); // 2f
Echo hexdec ('2f '); // 47
Decoct, octdec
Decoct-decimal to octal

Octdec-octal to decimal

The following is an example of the decoct and Dec dec functions:

Echo decoct (12); // 14
Echo octdec ('14'); // 12

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.