

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Floor the decimal values in MySQL instead of round?
You can use TRUNCATE() method to floor the values instead of round. Let us first create a table −
mysql> create table DemoTable ( Value DECIMAL(20,8) ); Query OK, 0 rows affected (0.54 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values(23.5654433); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(12.345542211); Query OK, 1 row affected, 1 warning (0.21 sec) mysql> insert into DemoTable values(12345.678543); Query OK, 1 row affected (0.22 sec)
Following is the query to display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----------------+ | Value | +----------------+ | 23.56544330 | | 12.34554221 | | 12345.67854300 | +----------------+ 3 rows in set (0.00 sec)
Here is the query to floor the decimal values instead of round −
mysql> update DemoTable set Value=truncate(Value,2); Query OK, 3 rows affected (0.20 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
This will produce the following output −
+----------------+ | Value | +----------------+ | 23.56000000 | | 12.34000000 | | 12345.67000000 | +----------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Python - Round number of places after the decimal for column values in a Pandas DataFrame
- In MySQL, how CEILING() and FLOOR() functions are different from ROUND() function?
- How to round correlation values in the correlation matrix to zero decimal places in R?
- Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())
- MySQL SUM function to add decimal values
- How to round the decimal number to the nearest tenth in JavaScript?
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL ROUND() function?
- Trying to round a calculation to two decimal places in a new column with MySQL?
- Output only the name of the month instead of the month number in MySQL
- How to round matrix values in R?
- Return the floor of the input in Numpy
- Java Program to Round a Number to n Decimal Places
- How to round a number to n decimal places in Java
- MySQL query to extract only the day instead of entire date
- Round records with numbers in MySQL
Advertisements