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.

4
  • 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. Commented Feb 18, 2016 at 3: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 Commented Feb 18, 2016 at 4:05
  • No, it means 15 digits in total. Integer types are safer for currency values because they avoid rounding errors. Commented Feb 18, 2016 at 4:10
  • Thank you, post your answer so I can mark it. Commented Feb 18, 2016 at 16:35

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.