简体   繁体   中英

How to convert a String type to Float type in MySQL/PHP?

I have a string like this:

$foo = "1.3223";

How do I convert $foo into a float ?

尝试投放:

$yourFloat = (float) $foo;

http://sg2.php.net/floatval

$foo = floatval($foo);

使用(float)投射:

$foo = (float) "1.3223";

This would do it:

<?php
$var = '122.34343The';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
?>

Remove the speech marks and PHP should convert into a float. or cast it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM