首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >表格的十进制字段在DB中的错误记录

表格的十进制字段在DB中的错误记录
EN

Stack Overflow用户
提问于 2018-07-24 08:35:19
回答 1查看 183关注 0票数 0

我想从'last_price‘= 9.12345678写入数据库值​​(在点之后需要8个字符)

CakePHP -数据库中的最后3.6.7,PHP7.2x64,MySQL 5.7x64,字段'last_price‘类型:十进制20,8

控制器:

代码语言:javascript
复制
 public function add ()
    {
        // debug ($ this-> request-> getData ());
        $ pair = $ this-> Pairs-> newEntity ();
        if ($ this-> request-> is ('post')) {
            $ pair = $ this-> Pairs-> patchEntity ($ pair, $ this-> request-> getData ());
            // debug ($ pair);
            if ($ this-> Pairs-> save ($ pair)) {
                $ this-> Flash-> success (__ ('The pair has been saved.'));
                return $ this-> redirect (['action' => 'index']);
            }
            $ this-> Flash-> error (__ ('The pair could not be saved. Please, try again.'));
        }
        $ exchanges = $ this-> Pairs-> Exchanges-> find ('list', ['limit' => 200]);
        $ this-> set (compact ('pair', 'exchanges'));
    }

内容$ this-> request-> getData ():

代码语言:javascript
复制
[
'exchange_id' => '1',
'title' => '12121',
'last_price' => '9.12345678',
'favorites' => '0'
]

PairsTable.php (模型)

代码语言:javascript
复制
$ validator
            -> decimal ('last_price', 8)
            // -> maxLength ('last_price', 30)
            -> requirePresence ('last_price', 'create')
            -> notEmpty ('last_price');

我单击以添加,但是数据库中有以下查询:

代码语言:javascript
复制
2018-07-24 07:09:19 Debug: duration = 0 rows = 1 INSERT INTO pairs (exchange_id, title, last_price, favorites, created, modified) VALUES (1, '5453534534543', '9.123457', 0, '2018 -07-24 07:09:19 ',' 2018-07-24 07:09:19 ')

为什么'last_price‘= 9.123457?!!?我明白了-它被写在数据库中为9.12345700。

为什么不是9.12345678?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-24 10:13:20

为了帮助您解决这个问题,我使用decimal_value (十进制(18,12))、float_value (浮点数(18,12))、double_value (双(18,12))设置了一个表。

三种插入物的double_value均准确。

将列类型更改为双列。清除orm_cache。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51494084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档