我有一个名为“Price”的表,其中有一个字段名为"value“,并设置为decimal。我希望能够插入一个字符串,如"3.5$“,mysql将插入数字"3.5”。到目前为止还没有成功。
发布于 2015-10-05 12:06:21
使用floatval
$NumberWithString = 3.5$;
floatval($NumberWithString);示例
<?php
$var = '122.34343The';
$float_value_of_var = floatval($var);
echo $float_value_of_var; // 122.34343
?>EDIT 01
或者使用preg_replace
$newNumber = preg_replace('/$/', '', $NumberWithString);发布于 2015-10-05 12:07:15
update yourtable
set yourdecimal = cast('3.7$' as decimal(10,2))
where id = 1https://stackoverflow.com/questions/32941082
复制相似问题