
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL - CAST DECIMAL to INT?
Cast DECIMAL to INT with the help of FLOOR() function. The syntax is as follows −
SELECT FLOOR(yourColumnName) from yourTableName where condition;
Let us first create a table. The following is the query to create a table.
mysql> create table DecimalToIntDemo -> ( -> Amount DECIMAL(3,1) -> ); Query OK, 0 rows affected (0.88 sec)
Now you can insert records into the table with the help of insert command. The query is as follows −
mysql> insert into DecimalToIntDemo values(12.5); Query OK, 1 row affected (0.23 sec) mysql> insert into DecimalToIntDemo values(50.4); Query OK, 1 row affected (0.18 sec) mysql> insert into DecimalToIntDemo values(48.6); Query OK, 1 row affected (0.10 sec)
Display all records with the help of select statement. The query is as follows −
mysql> select *from DecimalToIntDemo;
Here is the output −
+--------+ | Amount | +--------+ | 12.5 | | 50.4 | | 48.6 | +--------+ 3 rows in set (0.00 sec)
Apply the above syntax which we discussed in the beginning. The query is as follows −
mysql> SELECT FLOOR(Amount) from DecimalToIntDemo -> where Amount > 10;
The following is the output that cast decimal to int −
+---------------+ | FLOOR(Amount) | +---------------+ | 12 | | 50 | | 48 | +---------------+ 3 rows in set (0.00 sec)
Look at the above sample which gives only INT value.
- Related Articles
- How to cast from VARCHAR to INT in MySQL?
- MySQL CAST as DATE?
- int(5) vs. int(10) in MySQL?
- How Can MySQL CAST handle overflow?
- Convert INT to DATETIME in MySQL?
- How to cast DATETIME as a DATE in MySQL?
- How to use MySQL decimal?
- How to use the CAST function in a MySQL SELECT statement?
- How do I cast a type to a BigInt in MySQL?
- Changing Column in MySQL from int to double?
- How to convert bool to int in MySQL?\n
- How to store decimal in MySQL?
- MySQL BigInt zerofill vs int zerofill?
- MySQL data types int versus enum?
- Convert number INT in minutes to TIME in MySQL?

Advertisements