Reputation: 14417
I have a table with the column
name: variant_markup
datatype: numeric(4,3)
I try to put value 10.000 into it
And I get the Error
An error occurred while updating the entries
10.000 Out of range
It shouldn't be, and I have other columns with same data type and the same process to add a number in, and they don't complain!
The code:
decimal strippedMarkRate = decimal.Round(0, 3);
if (MarkUpTextBox.Text != string.Empty)
strippedMarkRate = decimal.Round(decimal.Parse(toolbox.removeChars(MarkUpTextBox.Text)), 3);
variant_markup = strippedMarkRate;
toolbox.removeChars function just removes any character that isn't a digit or a decimal point from the box, is there a way to do this with regex by anychance?
Upvotes: 0
Views: 715
Reputation: 1786
If you want to insert 10.000 then your data type needs to be defined as numeric(5,3). The first digit in the numeric type declaration is the maximum number of digits in the number (precision). In the case of 10.000, there are 5.
decimal and numeric (Transact-SQL)
decimal [ (p[ ,s] )] and numeric[ (p[ ,s] )]
...
p (precision) The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.
s (scale) The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.
Upvotes: 1
Reputation: 792
Perhaps your remove chars isn't doing what you need it to? As to you last question, it would probably be faster to remove the disallowed chars with a foreach statement like so:
StringBuilder sb = new StringBuilder();
foreach(char c in value)
{
if(char.IsDigit(c) || c == '.')
{
sb.append(c);
}
}
return sb.ToString();
Upvotes: 1