Laravel-4位小数的数字 [英] Laravel - Number with 4 decimals
问题描述
我想在数据库中存储1个数字和4个小数.
I want to store 1 number with 4 decimals, in my database.
如果我使用 float ,我只能添加2个小数位
If i use float i can add only 2 decimals
$table->float('sell');
如果我尝试使用十进制,则会收到错误消息
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 '
出售").(SQL:创建表 customers
( id
int unsigned not null auto_increment主键,出售
十进制(1,4)不为null, created_at
时间戳为空, updated_at
时间戳为空)默认字符集utf8整理utf8_unicode_ci)
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)
有帮助吗?
谢谢
推荐答案
使用以下内容;
$table->decimal('foo', 5, 4);
第一个参数是数字的总数,第二个参数是十进制精度".
The first parameter is the total number of numbers, the second parameter is the "decimal precision".
这篇关于Laravel-4位小数的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!