- 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
Truncate results in decimal to integer value with MySQL
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;
Output
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;
Output
This will produce the following output −
+-------------------+ | truncate(Value,0) | +-------------------+ | 45 | | 100 | | 15 | +-------------------+ 3 rows in set (0.00 sec)
Advertisements