ใช้ FORMAT() จัดรูปแบบตัวเลขให้มีคอมม่าและทศนิยม
สร้างตารางและเพิ่มข้อมูล
mysql> create table DemoTable ( Price decimal(10,4), Rate decimal(10,4) ); Query OK, 0 rows affected (0.96 sec)
mysql> insert into DemoTable values(1000,10.2); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(2000,20.4); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100,5); Query OK, 1 row affected (0.16 sec)
คิวรี่คูณและจัดรูปแบบ
mysql> select format((Price * Rate),2) from DemoTable;
ผลลัพธ์
+--------------------------+ | format((Price * Rate),2) | +--------------------------+ | 10,200.00 | | 40,800.00 | | 500.00 | +--------------------------+ 3 rows in set (0.00 sec)
FORMAT(number, decimals) จัดรูปแบบตัวเลขให้มีคอมม่าคั่นพันและกำหนดตำแหน่งทศนิยม ส่งคืนเป็นสตริง