Computer >> Máy Tính >  >> Lập trình >> MySQL

Làm cách nào để lưu trữ số thập phân PayPal trong cơ sở dữ liệu MySQL?

Để lưu trữ số tiền thập phân của PayPal trong cơ sở dữ liệu MySQL, bạn có thể sử dụng DECIMAL (10,2). Đầu tiên chúng ta hãy tạo một bảng -

mysql> create table DemoTable1491
   -> (
   -> Amount DECIMAL(10,2)
   -> );
Query OK, 0 rows affected (0.66 sec)

Chèn một số bản ghi vào bảng bằng lệnh chèn -

mysql> insert into DemoTable1491 values(987664.50);
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable1491 values(18783874.90);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1491 values(35363738.50);
Query OK, 1 row affected (0.15 sec)

Hiển thị tất cả các bản ghi từ bảng bằng câu lệnh select -

mysql> select * from DemoTable1491;

Điều này sẽ tạo ra kết quả sau -

+-------------+
| Amount      |
+-------------+
|   987664.50 |
| 18783874.90 |
| 35363738.50 |
+-------------+
3 rows in set (0.00 sec)