
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Display USD currency records with the correct format in MySQL
Use FORMAT() in MySQL to display USD currency records in the correct form. Let us first create a table −
mysql> create table DemoTable -> ( -> Amount DECIMAL(15,4) -> ); Query OK, 0 rows affected (0.75 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(90948484); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(1000000000); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values(1535353536); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values(773646463); Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output−
+-----------------+ | Amount | +-----------------+ | 90948484.0000 | | 1000000000.0000 | | 1535353536.0000 | | 773646463.0000 | +-----------------+ 4 rows in set (0.00 sec)
Here is the query to display currency records correctly in MySQL−
mysql> select concat('USD ',format(Amount,2)) as Currency from DemoTable;
This will produce the following output. Here, we are displaying USD currency records in the correct format−
+----------------------+ | Currency | +----------------------+ | USD 90,948,484.00 | | USD 1,000,000,000.00 | | USD 1,535,353,536.00 | | USD 773,646,463.00 | +----------------------+ 4 rows in set (0.23 sec)
- Related Articles
- MySQL Query to set currency records
- Format currency with Java MessageFormat
- Display records with more than two occurrences in MySQL?
- MySQL query to subtract date records with week day and display the weekday with records
- What should I do? Select int as currency or convert int to currency format in MySql?
- Format date while inserting records in MySQL
- Display selected records from a MySQL table with IN() operator
- Display records ignoring NULL in MySQL
- MySql how to display the records with latest ID in a table?
- Format date to display month names with the entire date in MySQL?
- MySQL query to display the count of distinct records from a column with duplicate records
- C# Currency ("C") Format Specifier
- Display distinct dates in MySQL from a column with date records
- Find and display duplicate records in MySQL?
- Display all records except one in MySQL

Advertisements