 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Format amount values for thousands number with two decimal places in MySQL?
For thousands number, use MySQL FORMAT(). Let us first create a −
mysql> create table DemoTable1394 -> ( -> Amount decimal(7,3) -> ); Query OK, 0 rows affected (0.68 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1394 values(60); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1394 values(2355.4); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable1394 values(456); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1394 values(8769); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select −
mysql> select * from DemoTable1394;
This will produce the following output −
+----------+ | Amount | +----------+ | 60.000 | | 2355.400 | | 456.000 | | 8769.000 | +----------+ 4 rows in set (0.00 sec)
Here is the query to format for thousands number with two decimal places −
mysql> select format(Amount,2) from DemoTable1394;
This will produce the following output −
+------------------+ | format(Amount,2) | +------------------+ | 60.00 | | 2,355.40 | | 456.00 | | 8,769.00 | +------------------+ 4 rows in set (0.00 sec)
Advertisements
 