protect overflow of sql data type decimal(9,3)

  • Thread starter Thread starter Zeng
  • Start date Start date
Z

Zeng

Hello,

I have many fields in my SQL database that are of type decimal(9,3). How do
I detect a decimal value (type decimal in C#) will overflow the db column of
sql type decimal (9,3)? Is there a way to figure out the min/max constants
of decimal(9,3) to compare against in C# to make sure the new value is "in
bound"?

Thanks!
-zeng
 
If you know that the SqlDecimal precision is 9 and the scale is 3, you can
simply do a range validation like the example below.

private bool IsInBound(decimal DecimalValue)
{
if((DecimalValue > 999999.999m) || (DecimalValue < -999999.999m))
return false;
return true;
}
 
Back
Top