What is to be used to store floats in MySQL?


To store floats in MySQL, you can use the concept of DECIMAL(). Let us first create a table −

mysql> create table DemoTable
   (
   Price DECIMAL(10,2)
   );
Query OK, 0 rows affected (1.59 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(874674.50);
Query OK, 1 row affected (0.39 sec)
mysql> insert into DemoTable values(9948984.20);
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable values(12345678.99);
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

Output

+-------------+
| Price       |
+-------------+
| 874674.50   |
| 9948984.20  |
| 12345678.99 |
+-------------+
3 rows in set (0.00 sec)
raja
Published on 14-Jun-2019 11:20:14
Advertisements