如何將數字格式化為小數以將其儲存在 MySQL 中?


在 MySQL 中無需將數字格式化,為此使用 DECIMAL 資料型別。讓我們先建立一個表 -

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

使用插入命令在表中插入一些記錄 -

mysql> insert into DemoTable1330 values(10944.7893);
Query OK, 1 row affected, 1 warning (0.13 sec)
mysql> insert into DemoTable1330 values(9848.44);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable1330 values(8009.90);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1330 values(1000.99);
Query OK, 1 row affected (0.13 sec)

使用 select 語句顯示錶中的所有記錄 -

mysql> select * from DemoTable1330;

這將產生以下輸出 -

+----------+
| Amount   |
+----------+
| 10944.79 |
| 9848.44  |
| 8009.90  |
| 1000.99  |
+----------+
4 rows in set (0.00 sec)

更新於: 05 年 11 月 2019

161 次瀏覽

開啟你的職業生涯

透過完成課程獲得認證

開始
廣告