Cruze
Cruze

Reputation: 220

Laravel not saving decimal numbers

Having issue with Laravel 5.3, PHP 7.2 and a currency field.

This is my migration script, i changed the amount field to decimal too but doesnt work.

public function up()
{
    Schema::create('order_details', function(Blueprint $table)
    {
        $table->integer('id', true);
        $table->integer('order_id');
        $table->string('product_id', 15);
        $table->string('unit', 10);
        $table->double('price', 10,2)->default(0.00);
        $table->double('quantity', 10, 2)->default(0);
        $table->double('amount', 18,2)->default(0.00);


        $table->double('sup_price',10,2)->default(0.00);
        $table->double('sup_quantity',4,2)->default(0);
        $table->double('sup_amount',18,2)->default(0.00);
    });
}

in my controller I have hardcoded the value

$modelName->amount = 24.87;
$modelName->save();

When I looked into the DB it is just storing 24.

What could be wrong with it. Thanks

Upvotes: 3

Views: 2483

Answers (1)

try with this:

$modelName->amount = number_format(24.87, 2, '.', '');

This works for m

Upvotes: 2

Related Questions