I. Numeric data types
Numeric or numeric data is typically two types of double and int in PHP.
PHP is a loosely typed scripting language, paying attention to the way the type is converted.
Copy CodeThe code is as follows:
$a = ' 5 ';
A string of numbers is also a number, which participates in mathematical operations when numbers are processed
echo is_numeric ($a); 1
Echo '
';
echo 7 + $a; 12
Echo '
';
Echo ' 7 ' + $a; 12
Echo '
';
Use. After connection, press string processing
Echo ' 7 '. $a; 75
?>
Two. Random number
The Rand () function is a simple wrapper for a random function defined in libc.
The Mt_rand () function is a good substitute for implementation.
Copy CodeThe code is as follows:
$a = rand (0,10);
echo $a;
Echo '
';
Echo Getrandmax ();
Echo '
';
$b = Mt_rand (0,10);
Echo $b;
Echo '
';
Echo Mt_getrandmax ();
Echo '
';
?>
Output
1
32767
6
2147483647
Three. Formatting data
Copy CodeThe code is as follows:
$a = 12345.6789;
Used to set how many decimal points are reserved
Echo Number_format ($a, 2);
Echo '
';
You can also change the symbolic representation of the default decimal point and the symbol for the thousand-bit
Echo Number_format ($a, 2, ' # ', ' * ')
?>
Output
12,345.68
12*345#68
Four Mathematical functions
Minimum value or minimum value in array
functions |
features |
abs () |
Take absolute value |
floor () |
Rounding rounding |
ceil () |
into a method rounding |
round () |
Rounding |
min () |
max () /p> |
To find the maximum or maximum value in the array |
Copy CodeThe code is as follows:
$a =-123456.789;
$b = Array (1, 2, 3, 4);
Echo ABS ($a);
Echo '
';
echo floor ($a);
Echo '
';
echo ceil ($a);
Echo '
';
Echo round ($a);
Echo '
';
Echo min ($b);
Echo '
';
echo Max ($b);
?>
Output
123456.789
-123457
-123456
-123457
1
4
http://www.bkjia.com/PHPjc/324809.html www.bkjia.com true http://www.bkjia.com/PHPjc/324809.html techarticle I. Numeric data type numeric or numeric data in PHP are generally two types of double and int. PHP is a loosely typed scripting language, paying attention to the way the type is converted. Copy code code as follows ...