Numeric or numeric data are generally two types of double and int in PHP. PHP is a loose scripting language. note the type conversion method. 1. 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.
The code is as follows:
$ 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'
';
Echo 7 + $ a; // 12
Echo'
';
Echo '7' + $ a; // 12
Echo'
';
// 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.
The code is as follows:
$ A = rand (0, 10 );
Echo $;
Echo'
';
Echo getrandmax ();
Echo'
';
$ B = mt_rand (0, 10 );
Echo $ B;
Echo'
';
Echo mt_getrandmax ();
Echo'
';
?>
Output
1
32767
6
2147483647
3. Format data
The code is as follows:
$ A = 12345.6789;
// Sets the number of decimal places to be retained.
Echo number_format ($ a, 2 );
Echo'
';
// 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. |
The code is as follows:
$ A =-123456.789;
$ B = array (1, 2, 3, 4 );
Echo abs ($ );
Echo'
';
Echo floor ($ );
Echo'
';
Echo ceil ($ );
Echo'
';
Echo round ($ );
Echo'
';
Echo min ($ B );
Echo'
';
Echo max ($ B );
?>
Output
123456.789
-123457
-123456
-123457
1
4