Division Operator (/)

Syntax

/

Description

Division operator. Dividing by zero will return NULL. By default, returns four digits after the decimal. This is determined by the server system variable div_precision_increment which by default is four. It can be set from 0 to 30.

Dividing by zero returns NULL. If the ERROR_ON_DIVISION_BY_ZERO SQL_MODE is used (the default since MariaDB 10.2.4), a division by zero also produces a warning.

Examples

SELECT 4/5;
+--------+
| 4/5    |
+--------+
| 0.8000 |
+--------+

SELECT 300/(2-2);
+-----------+
| 300/(2-2) |
+-----------+
|      NULL |
+-----------+

SELECT 300/7;
+---------+
| 300/7   |
+---------+
| 42.8571 |
+---------+

Changing div_precision_increment for the session from the default of four to six:

SET div_precision_increment = 6;

SELECT 300/7;
+-----------+
| 300/7     |
+-----------+
| 42.857143 |
+-----------+

SELECT 300/7;
+-----------+
| 300/7     |
+-----------+
| 42.857143 |
+-----------+

See Also

This page is licensed: GPLv2, originally from fill_help_tables.sql

Last updated

Was this helpful?