Laravel Eloquent将数据类型截断为double [英] Laravel Eloquent truncates the data type double
问题描述
Laravel截断double类型的值.
Laravel truncate value of type double.
值3.539363636363637 显示为3.5393636363636
The value 3.539363636363637 is showed as 3.5393636363636
我这样做是
$e=Enrollment::find(173);
dd($e->value);
// show 3.5393636363636
在phpmyadmin中,该值是正确的3.539363636363637
In phpmyadmin the value is correct 3.539363636363637
推荐答案
Laravel不会截断您的数据; PHP是. PHP中浮点数的默认精度为14个有效数字.如果要将精度提高到16位,则可以正确打印值.
Laravel is not truncating your data; PHP is. The default precision for floating point numbers in PHP is 14 significant digits. If you were to raise your precision up to 16 digits, your value would print fine.
PhpMyAdmin显示正确"的值,因为它将其视为字符串.实际上,它永远不会将其转换为浮点数.
PhpMyAdmin is showing the "correct" value because it treats it as a string; it never actually converts it to a floating point number.
ini_set('precision', 16);
$e=Enrollment::find(173);
dd($e->value);
// would show 3.539363636363637 (all 16 significant digits)
这篇关于Laravel Eloquent将数据类型截断为double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!