MySQL To define a column with the data type column_name DECIMAL(P,D); In the above syntax:
Like the INT data type, the If you use The following example defines a column called amount DECIMAL(6,2); In this example, MySQL allows the following syntax: column_name DECIMAL(P); This is equivalent to: column_name DECIMAL(P,0); In this case, the column contains no decimal part or decimal point. Moreover, we can even use the following syntax. column_name DECIMAL; In this case, the default value of MySQL DECIMAL storage MySQL allocates storage space for the integer and decimal parts separately. MySQL stores For each part,
For example, MySQL DECIMAL data type and monetary data Monetary data such as prices, salaries, account balances, etc. often use the amount DECIMAL(19,2); However, if you want to comply with Generally Accepted Accounting Principles (GAAP) rules, the currency column must contain at least amount DECIMAL(19,4); MySQL DECIMAL Data Type Example First, create a new table called CREATE TABLE test_order ( id INT AUTO_INCREMENT PRIMARY KEY, description VARCHAR(255), cost DECIMAL(19,4) NOT NULL ); The second step is to insert data into the test_order table. INSERT INTO test_order(description,cost) VALUES('Bicycle', 500.34),('Seat',10.23),('Break',5.21); The third step is to query data from the test_order table. SELECT * from test_order
Step 4. Change ALTER TABLE test_order MODIFY cost DECIMAL(19,4) zerofill; Step 5. Query the test_order table again. SELECT * from test_order Query results: As you can see above, there are many zeros filled in the output values. Because of zerofill, we will get an error when we insert a negative value:
Other insertion test conclusions: When the value is within the range and has extra decimal places, the extra decimal places will be truncated directly after rounding. If the value is outside the range, an Out of range value error will be reported directly. This is the end of this article about the detailed usage of the MySQL data type DECIMAL. For more information about the MySQL data type DECIMAL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed usage of js array forEach instance
>>: Windows Server 2016 Remote Desktop Services Configuration and License Activation (2 Users)
The problems and solutions encountered when deplo...
In the latest version of WIN10, Microsoft introdu...
Table of contents DML statements 1. Insert record...
Table of contents Some basic instructions 1. Chec...
Preface: MySQL master-slave architecture should b...
Basic structure: Copy code The code is as follows:...
Preface: Because many business tables use design ...
Table of contents Preface 1. Preparation 2. Insta...
What is vuex vuex: is a state manager developed s...
Preface This article records how I use docker-com...
Let’s look at an example first Copy code The code ...
A few days ago, I wrote an article about using CS...
This article shares the specific code of js to re...
Vue implements the palace grid rotation lottery (...
The format is simple: proxy_pass URL; The URL inc...