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

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

WBOY
Release: 2016-06-13 12:07:26
Original
2142 people have browsed it

字段类型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 />
Copy after login

101.5 

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

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template