A very common error when working with type numeric(precisão, escala)
is to find that precision indicates how many digits will fit in the whole part.
In fact, accuracy will indicate how many digits the integer will have, including the decimal places.
See the following example:
SELECT CAST(123456 AS NUMERIC(6, 4))
It will pop the field as it will be interpreted as 123456.0000
So, for the example type, the highest value that will fit in the field is 99.9999
Even the value 99.99999 will not be accepted as it will end up being rounded to 100.0000
Already the value 99.99994 will be accepted as it will be rounded to 99.9999
To know the highest value accepted by a NUMERIC field, do ((10 ^ precisão)/(10 ^ escala)) - (1/(10^escala))
Example using NUMERIC(3, 3)
((10 ^ 3)/(10 ^ 3)) - (1/(10 ^ 3))
(1000/1000) - (1/1000)
1 - 0.001
0.999
This is one of the situations I learned from day to day, because not even the manual informs the formula of knowing what the greatest value of a field.
Note: You can not have field precision less than the