PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] Laravel - Number with 4 decimals

 March 11, 2022     eloquent, laravel, laravel-5, laravel-5.2, sql     No comments   

Issue

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


Solution

Use the following;

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

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



Answered By - Darren Taylor
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing