gpt4 book ai didi

php - MySql 在 DDBB 上的浮点字段上记录时将浮点值转换为整数

转载 作者:行者123 更新时间:2023-11-29 02:54:01 24 4
gpt4 key购买 nike

我有这个更新查询:

 UPDATE ws_users SET us_credits='251181.5' WHERE us_id=2;

如您所见,us_credits 字段是一个默认值为零的 float 字段:

im

每个尝试将浮点值设置为 us_credits 的 UPDATE 查询都会得到一个整数,例如,查询首先在该字段的 251182 记录中键入结果。

如果我尝试手动更改记录,如上所示,它既不记录浮点值,只记录整数(在本例中为 251184):

img

最佳答案

MySQL permits a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here, “(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point.For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.

https://dev.mysql.com/doc/refman/5.0/en/floating-point-types.html

因此您还需要定义用于处理小数点的列。

关于php - MySql 在 DDBB 上的浮点字段上记录时将浮点值转换为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32694121/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com