Heim > Datenbank > MySQL-Tutorial > Hauptteil

注意mysql 中一订要用decimal标识货币的值

WBOY
Freigeben: 2016-06-07 16:25:16
Original
1229 Leute haben es durchsucht

注意mysql 中一定要用decimal标识货币的值 注意mysql 中一定要用decimal标识货币的值!不要用float了,举例说明: Create Table LedgerEntries ( LedgerEntryID Int Primary Key Auto_Increment Not Null ,CustomerID Int Not Null ,Amount Float Not Null );

注意mysql 中一定要用decimal标识货币的值
注意mysql 中一定要用decimal标识货币的值!不要用float了,举例说明:
  
Create Table LedgerEntries
(
LedgerEntryID Int Primary Key Auto_Increment Not Null
,CustomerID Int Not Null
,Amount Float Not Null
);

然后插入一些数据;
Insert Into LedgerEntries (CustomerID, Amount)
Values (1, 3.14);

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

最后查询下
Select * From LedgerEntries;

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



看到了么?没了最后的一位!,因此,赶紧用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 (CustomerID, 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 (CustomerID, 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)



  
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!