table('users')." set yujia=yujia+".$yujia." where user_id=".$user_id;$db->"/> table('users')." set yujia=yujia+".$yujia." where user_id=".$user_id;$db->">

Home >Backend Development >PHP Tutorial >字段类型decimal(10,1),计算100.0+1.5=101.0,为啥

字段类型decimal(10,1),计算100.0+1.5=101.0,为啥

WBOY
WBOYOriginal
2016-06-13 12:07:262161browse

字段类型decimal(10,1),计算100.0+1.5=101.0,为什么?
$sql = "update ".$fdyu->table('users')." set yujia=yujia+".$yujia." where user_id=".$user_id;
$db->query($sql);

yujia字段类型为decimal(10,1),假如原yujia字段中的数值是100.0,现在我提交$yujia=1.5,结果yujia字段的值是101.0,少了0.5,为什么?
------解决思路----------------------

create temporary table t (n decimal(10,1));<br /><br />insert into t values (100.0);<br /><br />update t set n=n+1.5;<br /><br />select * from t<br />

101.5 

------解决思路----------------------
intval轉整形過濾掉小數。。
改用floatval就可以了

Statement:
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