I have a column with datatype numeric(18,3)
. The user can enter decimal numbers as well. I have set the max length of this text box to 18 but when I type 777777777777777777, I get this error
Arithmetic overflow error converting varchar to data type numeric
Can someone explain me why I am getting this error?
Because numeric(18,3)
means: 18 digits in total, thereof 3 after the decimal point - so you only get 15 digits before the decimal point.
Entering 18 digits (before the decimal point) will obviously cause an overflow!
If you really need 18 digits before the decimal point, you need to define your column as numeric(21,3)
ALTER TABLE dbo.TableName
ALTER COLUMN MinimumValue NUMERIC(21, 3)
For more details, read the fabulous docs