Storage for MySQL currency field type

Source: Internet
Author: User
Tags mysql in

The loat type can be a floating-point number (that is, a decimal type), but float has a downside, and when the data you give is an integer, it is treated as an integer. So we have a natural problem in accessing the currency value, my default value is: 0.00 and the actual storage is 0, the same I access the currency is 12.00, the actual storage is 12.
Fortunately MySQL offers two data types: Numeric and decimal, both of which can be easily resolved with the above problem:
The NUMERIC and DECIMAL types are implemented by MySQL in the same type, which is allowed in the SQL92 standard. They are used to hold values that have important requirements for accurate precision, such as money-related data. When declaring a column with one of them, the precision and range of values can (usually) be specified, for example:
Salary DECIMAL (5,2)
In this example, 5 (precision (precision)) represents the number of important decimal digits, and 2 (scale) represents the number of digits after the decimal point. In this case, therefore, the salary column can store a range of values from 99.99 to 99.99. (In fact, the value that MySQL can store in this column can be up to 999.99, because it doesn't store a positive sign).
Translator Note:
The effect of M and D on the range of decimal (M, d) values
Type description value range (MySQL < 3.23) range (MySQL >= 3.23)
DECIMAL (4, 1)-9.9 to 99.9-999.9 to 9999.9
DECIMAL (5, 1)-99.9 to 999.9-9999.9 to 99999.9
DECIMAL (6, 1)-999.9 to 9999.9-99999.9 to 999999.9
DECIMAL (6, 2)-99.99 to 999.99-9999.99 to 99999.99
DECIMAL (6, 3)-9.999 to 99.999-999.999 to 9999.999
# in MySQL 3.23 and later versions, the value range of decimal (M, d) equals the range of decimal (M + 2, D) in earlier versions.
There is also a kind of data type is also relatively good: that is Longblob, this data type can be directly stored in the image file in the database!

Storage for MySQL currency field type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.