Reputation: 634
I am trying to save a double value in MySQl database with Laravel. But only two digits after the dot are saving. I have 5 digits after the dot. For example, my value is 0.01197. But when I saved in database, it only shows 0.01. Rest of the digits are not saved.
I am using Laravel 5.6 with PHP 7.1.2 and MariaDB 10.1.29 version. Here is my DB migration code:
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();
});
}
Here is the controller code for saving the value into 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,
]);
I have tried changing the table column type into float and decimal. But it did not work. Can anyone please find the problem here? Thanks in advance.
Upvotes: 1
Views: 6520
Reputation: 506
In laravel :
DOUBLE equivalent with precision, 10 digits in total and 2 after the decimal point.
So change your migration file like:
$table->double('income_in_usd', 10, 5);
Upvotes: 4