php string number conversion method: 1. Use the intval function to convert the string into an integer, such as "intval($sum);"; 2. Use the floatval function to convert the string into a floating point number. Statements such as "floatval($sum);".
Recommended: "PHP Video Tutorial"
The operating environment of this tutorial: Windows7 system, PHP7.3.3, the The method is applicable to all brands of computers.
php7.3.3-Conversion between strings and numbers
In usual PHP projects, we often use it to convert strings and numbers. , today I will introduce to you the methods of converting between them.
Convert strings to numbers. Here we use two functions of PHP, intval() and floatval();
<?php $sum='99.99'; //利用intval函数将字符串转换为整数 echo intval($sum); echo '<hr/>'; //利用floatval函数将字符串转换为浮点数 echo floatval($sum);
Print results
99 99.99
To convert numbers to strings, here we can directly use PHP’s system function strval().
<?php $int=99; echo strval($int);
Print results
99
To summarize, intval() converts a string into a number, while the strval() function converts a number into a string.
The above is the detailed content of php string number conversion method. For more information, please follow other related articles on the PHP Chinese website!