php string number conversion method

藏色散人
Release: 2023-03-07 21:38:01
Original
2303 people have browsed it

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);".

php string number conversion method

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();

'; //利用floatval函数将字符串转换为浮点数 echo floatval($sum);
Copy after login

Print results

99 99.99
Copy after login

To convert numbers to strings, here we can directly use PHP’s system function strval().


        
Copy after login

Print results

99
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!