As documented under Arithmetic Operators:
In division performed with
/
, the scale of the result when using two exact-value operands is the scale of the first operand plus the value of thediv_precision_increment
system variable (which is 4 by default). For example, the result of the expression5.05 / 0.014
has a scale of six decimal places (360.714286
).
Therefore, either:
Increase
div_precision_increment
to suit your needs:SET div_precision_increment = 6;
Or, to set globally (i.e. across all future sessions):
SET GLOBAL div_precision_increment = 6;
Or even set it in the
[mysqld]
section of your option file / on the command-line to ensure that it survives server restarts.Explicitly cast the result of your operation to a type having your desired scale:
SELECT CAST(1 / 1000000 AS DECIMAL(10,8));