Laravel decimal and double datatype migration

How to make laravel decimal migration. Laravel double datatype migration. laravel decimal vs double dataType.

Laravel decimal() type migration

Laravel migration decimal() method create mysql DECIMAL type column. we pass total digit and after decimal digits in decimal() migration method. decimal datatype save exact numeric value.

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->decimal('amount', 8, 2);
    });
}

Laravel double() type migration

Laravel migration double() method create mysql DOUBLE type column. we pass total digit and after decimal digits in double() migration method. double datatype make numeric value rounded after given decimal points.

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->double('amount', 8, 2);
    });
}

Laravel decimal() vs double() type migration

laravel decimal datatype save exact numeric value and double datatype make numeric value rounded after given decimal points. decimal datatype used when it is important to preserve exact precision.

php laravel developer anmol sharma

Anmol Sharma

I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.

Random tutorial links