cakephp - 表格十进制字段的数据库中记录不正确
问题描述
我想在数据库中写入'last_price' = 9.12345678的值(点后需要8个字符)
CakePHP - last 3.6.7,PHP 7.2x64,MySQL 5.7x64,数据库中的字段“last_price”类型:DECIMAL 20、8
控制器:
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():
[
'exchange_id' => '1',
'title' => '12121',
'last_price' => '9.12345678',
'favorites' => '0'
]
PairsTable.php(模型)
$ validator
-> decimal ('last_price', 8)
// -> maxLength ('last_price', 30)
-> requirePresence ('last_price', 'create')
-> notEmpty ('last_price');
我单击添加,但以下查询将进入数据库:
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 ??
解决方案
推荐阅读
- parsing - 如何使用 megaparsec 报告多个错误?
- sqlite - 如何使用 lua 固件在 ESP8266 上运行 sqlite3?
- python - 使用 MDM 从 iOS 设备安装或删除应用程序时,我可以收到通知或任何观察者吗?
- celery - 如何知道 Celery 的所有任务都完成了?
- java - 如何使用 Android 在 Firebase 实时数据库中检索经过身份验证的用户的用户数据
- windows - PM2离线安装在Window Server上?
- javascript - $(document).ready() 内的 div 高度为零
- html - htaccess rewrite - 如何将域重定向到域
- python - 不使用 remove 或 fromkeys 删除重复项;列表切片;Python
- mysql - MYSQL Workbench 安装 - 架构未连接