Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Number with 4 decimals

I want to store 1 number with 4 decimals, in my database.

If i use float i can add only 2 decimals

$table->float('sell');

enter image description here


If I try with decimal i get an error

$table->decimal('sell', 1, 4);

The first number must be greater than or equal to the second number.

SQLSTATE[42000]: Syntax error or access violation: 1427 For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column '  

sell'). (SQL: create table customers (id int unsigned not null auto_increment primary key, sell decimal(1, 4) not null,
created_at timestamp null, updated_at timestamp null) default character set utf8 collate utf8_unicode_ci)

Any help?

Thanks

like image 351
confm Avatar asked Nov 28 '22 04:11

confm


2 Answers

Use the following;

$table->decimal('foo', 5, 4);

The first parameter is the total number of numbers, the second parameter is the "decimal precision".

like image 64
Darren Taylor Avatar answered Nov 29 '22 17:11

Darren Taylor


In your schema file.

 $table->decimal('your_field_name', 13, 4);
  • your_field_name = Database field name.
  • 13 = Total number of digit. Example- $99,999,999,999.99
  • 4 = value after decimal. Example - $999,999,999.9999
like image 31
Vinay Kaithwas Avatar answered Nov 29 '22 18:11

Vinay Kaithwas