- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the best datatype for currencies in MySQL?
The best data type for currencies in MySQL is a DECIMAL. The syntax of DECIMAL data type is as follows −
DECIMAL(TotalDigit,NumberOfDigitAfterDecimalPoint);
To understand the above syntax, let us create a table. The query to create a table is as follows −
mysql> create table CurrenciesDemo -> ( -> TotalPrice DECIMAL(10,2) -> ); Query OK, 0 rows affected (1.82 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into CurrenciesDemo values(1647575.67); Query OK, 1 row affected (0.19 sec) mysql> insert into CurrenciesDemo values(1647575); Query OK, 1 row affected (0.21 sec) mysql> insert into CurrenciesDemo values(99599596); Query OK, 1 row affected (0.13 sec) mysql> insert into CurrenciesDemo values(1986.50); Query OK, 1 row affected (0.23 sec) mysql> insert into CurrenciesDemo values(99999999.90); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from CurrenciesDemo;
The following is the output −
+-------------+ | TotalPrice | +-------------+ | 1647575.67 | | 1647575.00 | | 99599596.00 | | 1986.50 | | 99999999.90 | +-------------+ 5 rows in set (0.00 sec)
The following is the query to show all the above prices with prefix symbol like dollar −
mysql> select concat('$',TotalPrice) as DollerSign from CurrenciesDemo;
The following is the output −
+--------------+ | DollerSign | +--------------+ | $1647575.67 | | $1647575.00 | | $99599596.00 | | $1986.50 | | $99999999.90 | +--------------+ 5 rows in set (0.00 sec)
- Related Articles
- What is the smallest datatype for one bit in MySQL?
- For timestamp, which datatype is used in MySQL?
- What is the usage of ZEROFILL for INT datatype?
- What is the MySQL datatype to store DATALINK object in JDBC
- Which datatype should I use for flag in MySQL?
- What is the best fragrance for men?
- What are the popular Crypto Currencies in circulation?
- Which MySQL Datatype should be used for storing BloodType?
- What is the best treatment for Kidney failure?
- What is the best iOS apps for business?
- What is the best iOS app for education?
- What is Yellow Jaundice? What is the best treatment for it?
- How to set NOW() as default value for datetime datatype in MySQL?
- Best practices for using MySQL indexes?
- How to sum rows of VARCHAR datatype or TIME datatype in MySQL?

Advertisements