2
votes

So, I need to save amounts that go up to 999,999,999,999.99, and in the documentation of the Schema Builder of Laravel says that I can set up up to 15 digits and 8 decimals, but this is not working (https://laravel.com/docs/5.2/migrations#writing-migrations)

In Column Types says:

$table->double('column', 15, 8); DOUBLE equivalent with precision, 15 digits in total and 8 after the decimal point.

The line of code in my migration is the following:

$table->double('m1',12,2)->default(0)->nullable();

Any ideas? Thank you.

1
Well for a start 12 digits is not enough for a number with 14 digits. And if you're using these variables to store sums of money, then you really shouldn't be using floating point anyway. - r3mainer
@squeamishossifrage as I understand the documentation is that 15 stands for the digits (so 999,999,999,999 shouldn't be a problem) and 8 stands for the decimals. Am I wrong then? And why should I be using a floating point? Thanks - mkmnstr
No, it means 15 digits in total. Integer types are safer for currency values because they avoid rounding errors. - r3mainer
Thank you, post your answer so I can mark it. - mkmnstr

1 Answers

2
votes

try use:

 $table->decimal('m1',12,2)->default(0)->nullable();

if your values only positive... then use:

$table->decimal('m1',12,2)->unsigned()->default(0)->nullable();

works to me!