2

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.

andres.gtz
  • 624
  • 12
  • 22
  • 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 Feb 18 '16 at 03:59
  • @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 – andres.gtz Feb 18 '16 at 04:05
  • No, it means 15 digits *in total*. Integer types are safer for currency values because they avoid rounding errors. – r3mainer Feb 18 '16 at 04:10
  • Thank you, post your answer so I can mark it. – andres.gtz Feb 18 '16 at 16:35

1 Answers1

3

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!

Vinícius Medeiros
  • 2,763
  • 1
  • 11
  • 12