I’ve read 13.1.3 Fixed-Point Types (Exact Value) – DECIMAL, NUMERIC, but nothing about the topic is mentioned.
As far as I tested, I can INSERT
a string literal such as '123.45'
into a DECIMAL(5, 2)
column, but does this insertion lose precision?
Similarly, does SELECT
ing a DECIMAL
column as a string in any programming language lose accuracy?
Finally, this is what I want to ask the most: in which section of the official documentation are they explained? I want a strict understanding about the topic.
2
Answers
https://dev.mysql.com/doc/refman/8.0/en/precision-math-decimal-characteristics.html says:
https://dev.mysql.com/doc/refman/8.0/en/problems-with-float.html has an example that shows the effect of FLOAT imprecision, and that DECIMAL will not have the same issue.
Many programming languages use IEEE 754 format for a floating point numeric type. These all suffer the same imprecision issue.
You may want to read What Every Computer Scientist Should Know About Floating-Point Arithmetic. This is not part of the MySQL manual, but it applies to many programming languages.
MySQL
DECIMAL(m,n)
function data type is an exact numeric data type defined by its precision (total number of digits, m) and scale (number of digits to the right of the decimal point, n).Now, a decimal number define as:
First get the maximum possible numeric digits or whole number digits (x) of your data column and then find the round off digits (y).
So, m & n should be define as:
and relation between
m
&n
is:This is official documentation where explained it in details
DECIMAL Data Type Characteristics
I hope this will resolve your doubts