Jorre
Jorre

Reputation: 17581

change float to float with more precision in laravel 5.1

I have a database with two floats for latitude and longitude, but I see that they get cut off after two positions precision. Laravel seems to create DOUBLE(8,2) when migrating a float.

What I tried is change the float and add the number of positions to it, like so:

$table->float('latitude', 10, 8)->change();

That doesn't seem to do anything in laravel 5.1, the precision stays at only 2 positions. I tried the following as well:

$table->double('latitude', 10, 8)->change();

But that causes a crash on Doctrine\DBAL Unknown column type "double" requested.

Any ideas how I can change my existing columns for lat and lng into a more precies number with 8 positions precision?

Upvotes: 3

Views: 10524

Answers (2)

Kaushik shrimali
Kaushik shrimali

Reputation: 1228

If Unknown column type "double" requested.

use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\Type;



public function up()
{
    if (!Type::hasType('double')) {
        Type::addType('double', FloatType::class);
    }
    Schema::table('salary_process', function(Blueprint $table) {
        $table->double('total_working_days')->change()->nullable();
    }
}

Try this.

Upvotes: 2

ojrask
ojrask

Reputation: 2828

My precision needs were satisfied by using a DECIMAL column. Change your double call to a decimal call and see whether it helps.

I raised an issue here relating to this behaviour: https://github.com/laravel/framework/issues/13773

Upvotes: 3

Related Questions