我试图用Laravel在MySQl数据库中保存一个双值。但只有两位数字在点后面。我在点后面有5个数字。例如,我的值是0.01197。但当我保存在数据库中时,它只显示0.01。其余数字不保存。
我使用的是Laravel 5.6和PHP 7.1.2以及MariaDB 10.1.29版本。这是我的数据库迁移代码:
public function up()
{
Schema::create('earnings', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('content_id');
$table->foreign('content_id')->references('id')->on('contents');
//this is the line for saving double value
$table->double('income_in_usd', 10, 2);
$table->timestamps();
});
}
下面是将值保存到DB的控制器代码:
$earning_id = DB::table('earnings')->insertGetID([
'month' => $request->month,
//here I am saving my double values
'income_in_usd' => $value['net_revenue'],
'exchange_rate' => $request->exchange_rate,
'income_in_bdt' => $value['net_revenue'] * $request->exchange_rate,
'content_id' => $content->id,
]);
我已尝试将表列类型更改为float和decimal。但没用。有人能在这里找到问题吗?提前谢谢。
最佳答案
在拉腊维尔:
精度为双倍,共10位,小数点后2位。
因此,请更改迁移文件,如下所示:
$table->double('income_in_usd', 10, 5);
关于php - 在Laravel 5和MySQL中, double 值点后仅保存两位数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51183921/