Tutorialspoint

1 Answer
karthikeya Boyini

Use truncate() for this, for example, 190.245 to 190. Following is the syntax −

select truncate(yourColumnName,0) from yourTableName;

Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Value DECIMAL(10,4)
   -> );
Query OK, 0 rows affected (0.67 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values(45.567);
Query OK, 1 row affected (0.12 sec)

mysql> insert into DemoTable values(100.0000);
Query OK, 1 row affected (0.17 sec)

mysql> insert into DemoTable values(15.89000);
Query OK, 1 row affected (0.25 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+----------+
| Value    |
+----------+
| 45.5670  |
| 100.0000 |
| 15.8900  |
+----------+
3 rows in set (0.00 sec)

Here is the query to truncate results from SQL to integer value.

mysql> select truncate(Value,0) from DemoTable;

This will produce the following output −

+-------------------+
| truncate(Value,0) |
+-------------------+
| 45                |
| 100               |
| 15                |
+-------------------+
3 rows in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.