Note that you must use decimal to identify the currency value in mysql.

Source: Internet
Author: User
Be sure to use decimal to identify the currency value in mysql. Be sure to use decimal to identify the currency value in mysql! Do not use float. For example: CreateTableLedgerEntries (LedgerEntryIDIntPrimaryKeyAuto_IncrementNotNull, CustomerIDIntNotNull, AmountFloatNotNull );

Be sure to use decimal to identify the currency value in mysql. Be sure to use decimal to identify the currency value in mysql! Do Not use float. Example: Create Table LedgerEntries (LedgerEntryID Int Primary Key Auto_Increment Not Null, CustomerID Int Not Null, Amount Float Not Null );

Note: mysql must use decimal to identify the currency value.
Note that decimal must be used to identify the currency value in mysql! Do not use float. For example:

Create Table LedgerEntries
(
LedgerEntryID Int Primary Key Auto_Increment Not Null
, CustomerID Int Not Null
, Amount Float Not Null
);

Then insert some data;
Insert Into LedgerEntries (mermerid, Amount)
Values (1, 3.14 );

Insert Into LedgerEntries (mermerid, Amount)
Values (1, 30000.14 );

Last Query
Select * From LedgerEntries;

+ --------------- + ------------ + --------- +
| LedgerEntryID | CustomerID | Amount |
+ --------------- + ------------ + --------- +
| 1 | 1 | 3.14 |
| 2 | 1 | 30000.1 |
+ --------------- + ------------ + --------- +



Have you seen it? No last one !, Therefore, use decimal.

Create Table LedgerEntries
(
LedgerEntryID Int Primary Key Auto_Increment Not Null
, CustomerID Int Not Null
, Amount Decimal (10, 2) Not Null
);

Insert Into LedgerEntries (mermerid, Amount)
Values (1, 3.14 );

-- This is the largest value we can insert into a Decimal (10, 2)
-- If we have two numbers to the right of the decimal point
Insert Into LedgerEntries (mermerid, Amount)
Values (1, 99999999.99 );

Select * From LedgerEntries;
+ --------------- + ------------ + ------------- +
| LedgerEntryID | CustomerID | Amount |
+ --------------- + ------------ + ------------- +
| 1 | 1 | 3.14 |
| 2 | 1 | 99999999.99 |
+ --------------- + ------------ + ------------- +
2 rows in set (0.00 sec)

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.