
- 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
What should I do? Select int as currency or convert int to currency format in MySql?
To convert int to current format, use CONCAT() with FORMAT() function from MySQL.
The syntax is as follows −
SELECT CONCAT(‘CurrencySymbol’,FORMAT(yourColumnName,valueAfterDecimal)) as AnyVariableName from yourTableName;
To understand the above syntax, let us create a table. The query to create a table −
mysql> create table AddingCurrencySymbolDemo −> ( −> Amount int −> ); Query OK, 0 rows affected (1.50 sec)
Insert records in the table using insert command. The query is as follows −
mysql> insert into AddingCurrencySymbolDemo values(250); Query OK, 1 row affected (0.22 sec) mysql> insert into AddingCurrencySymbolDemo values(500); Query OK, 1 row affected (0.22 sec) mysql> insert into AddingCurrencySymbolDemo values(1000); Query OK, 1 row affected (0.16 sec) mysql> insert into AddingCurrencySymbolDemo values(750); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from AddingCurrencySymbolDemo;
The following is the output −
+--------+ | Amount | +--------+ | 250 | | 500 | | 1000 | | 750 | +--------+ 4 rows in set (0.00 sec)
Here is the query to convert int to currency format. The query is as follows −
mysql> select concat('$',format(Amount,0)) as AddedCurrency from AddingCurrencySymbolDemo;
The following is the output displaying current format −
+---------------+ | AddedCurrency | +---------------+ | $250 | | $500 | | $1,000 | | $750 | +---------------+ 4 rows in set (0.00 sec).
- Related Articles
- How can I format numbers as dollars currency string in JavaScript?
- Convert INT to DATETIME in MySQL?
- Format currency with Java MessageFormat
- C# Currency ("C") Format Specifier
- How do I multiply an unsigned int by -1 on a MySQL SELECT?
- Should I store a field PRICE as an int or as a float in the database?
- Display USD currency records with the correct format in MySQL
- What does the method fill(int[], int fromIndex, int toIndex, int val) do in java?
- What does the method copyOfRange(int[] original, int from, int to) do in java?
- How do I convert a char to an int in C and C++?
- What does the method sort(int[] a, int fromIndex, int toIndex) do in java?
- How to convert bool to int in MySQL?\n
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- Convert number INT in minutes to TIME in MySQL?
- MySQL Query to set currency records

Advertisements