![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How do I format a number as decimal to store it in MySQL?
You do not need to format a number in MySQL, for this use DECIMAL data type. Let us first create a table −
mysql> create table DemoTable1330 -> ( -> Amount DECIMAL(10,2) -> ); Query OK, 0 rows affected (0.85 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1330 values(10944.7893); Query OK, 1 row affected, 1 warning (0.13 sec) mysql> insert into DemoTable1330 values(9848.44); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1330 values(8009.90); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1330 values(1000.99); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1330;
This will produce the following output −
+----------+ | Amount | +----------+ | 10944.79 | | 9848.44 | | 8009.90 | | 1000.99 | +----------+ 4 rows in set (0.00 sec)
Advertisements