Those things about MySQL (3) How decimals are stored

Source: Internet
Author: User

When you create a MySQL data table, you often encounter storage decimals (floating point numbers), such as: Price, weight, height, etc.

There are three types of storage solutions prevalent in large companies:

1, the data to expand the multiples of 10 to use integer type storage purposes.

For example, the price, we often divided into units for storage, that is, to expand the data 100 times times, so that the meta-component storage.

Weight can be in grams, if grams or decimals, in MG, micrograms and other units for storage.

2. Store using the decimal type

such as the price, we can use two decimal places to store the precision. It is strongly not recommended to use float or double type storage, there will be a loss of precision, in the future when the value comparison, prone to incorrect results.

3, fractional and integer parts are stored separately.

For example, the price of 3.14, we saved into two fields, a field storage 3, a field storage 14, generally less use. When the stored data range is outside the range of decimal, you can split the data by integers and decimals.

The first option is recommended here.

Those things about MySQL (3) How decimals are stored

Related Article

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: 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.