mercredi 4 juillet 2018

Only two digits are saving after dot in double value in Laravel 5 and MySQL

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.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire