Field type decimal (100.0), calculated 1.5 + 101.0 =, why?

Source: Internet
Author: User
Field type decimal (100.0), calculate + 1.5101.0, why? $ SQL = "update". $ fdyu-> table ('users'). "set yujia = yujia +". $ yujia. "where user_id =". $ user_id;
$ Db-> query ($ SQL );

The yujia field type is decimal (100.0). If the value in the original yujia field is 1.5, I submit $ yujia = 101.0. The result is that the value of the yujia field is 0.5, which is less. why?


Reply to discussion (solution)

Create temporary table t (n decimal (100.0); insert into t values (1.5); update t set n = n +; select * from t
N
101.5

I found the reason. it turns out that my variable uses an integer.
$ Yujia = isset ($ _ REQUEST ['yujia '])? Intval (trim ($ _ REQUEST ['yujia ']): 0;

Intval? Integer ?? Drop small ?..
Use floatval instead.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.