How to get number located at 2 places before decimal point MySQL?

MySQLMySQLi Database

In order to get number located at 2 places before decimal point, you can use the concept of div.

Let us create a table −

mysql> create table demo1
−> (
−> value float
−> );
Query OK, 0 rows affected (2.20 sec)

Insert some records into the table with the help of insert command −

mysql> insert into demo1 values(456.54);
Query OK, 1 row affected (0.16 sec)
mysql> insert into demo1 values(50.64);
Query OK, 1 row affected (0.17 sec)
mysql> insert into demo1 values(1000.78);
Query OK, 1 row affected (0.13 sec)

Display records from the table using select statement −

mysql> select *from demo1;

This will produce the following output −

+---------+
| value   |
+---------+
| 456.54  |
| 50.64   |
| 1000.78 |
+---------+
3 rows in set (0.02 sec)

Following is the query to get number located at 2 places before decimal point.

mysql> select value div 10%10 from demo1;

This will produce the following output −

+-----------------+
| value div 10%10 |
+-----------------+
|               5 |
|               5 |
|               0 |
+-----------------+
3 rows in set (0.03 sec)
raja
Published on 19-Nov-2020 10:36:00
Advertisements