It uses a mathematical approach.
private static bool IsValidSqlDecimal(decimal value, int precision, int scale) { var minOverflowValue = (decimal)Math.Pow(10, precision - scale) - (decimal)Math.Pow(10, -scale) / 2; return Math.Abs(value) < minOverflowValue; }
This takes into account how the sql server will do rounding and prevent overflow errors, even if we exceed accuracy. For instance:
DECLARE @value decimal(10,2) SET @value = 99999999.99499
source share