I. Numerical Data Type
Numeric or numeric data are generally two types of double and int in PHP.
PHP is a loose scripting language. Pay attention to the type conversion method.
Copy codeThe Code is as follows:
<? Php
$ A = '5 ';
// The string of a number is also a number, which is used in mathematical operations as a number.
Echo is_numeric ($ a); // 1
Echo '<br/> ';
Echo 7 + $ a; // 12
Echo '<br/> ';
Echo '7' + $ a; // 12
Echo '<br/> ';
// Use. After the connection, it will be processed by string
Echo '7'. $ a; // 75
?>
Ii. Random Number
The Rand () function is a simple package for a random function defined in libc.
The Mt_rand () function is a good substitute for implementation.
Copy codeThe Code is as follows:
<? Php
$ A = rand (0, 10 );
Echo $;
Echo '<br/> ';
Echo getrandmax ();
Echo '<br/> ';
$ B = mt_rand (0, 10 );
Echo $ B;
Echo '<br/> ';
Echo mt_getrandmax ();
Echo '<br/> ';
?>
Output
1
32767
6
2147483647
3. format data
Copy codeThe Code is as follows:
<? Php
$ A = 12345.6789;
// Sets the number of decimal places to be retained.
Echo number_format ($ a, 2 );
Echo '<br/> ';
// You can also change the default decimal point and the decimal point.
Echo number_format ($ a, 2 ,'#','*')
?>
Output
12,345.68
12*345 #68
Iv. mathematical functions
Function |
Function |
Abs () |
Take absolute value |
Floor () |
Rounding |
Ceil () |
Returns an integer. |
Round () |
Rounding |
Min () |
Minimum value or the minimum value in the array |
Max () |
Returns the maximum value or the maximum value in the array. |
Copy codeThe Code is as follows:
<? Php
$ A =-123456.789;
$ B = array (1, 2, 3, 4 );
Echo abs ($ );
Echo '<br/> ';
Echo floor ($ );
Echo '<br> ';
Echo ceil ($ );
Echo '<br> ';
Echo round ($ );
Echo '<br> ';
Echo min ($ B );
Echo '<br> ';
Echo max ($ B );
?>
Output
123456.789
-123457
-123456
-123457
1
4