I need to store a value taken from a form into a column which is a decimal(4,0)
.
First (in the controller) I take the value from the form and I convert it from string to decimal and multiply it for 100 so I'm able to keep the values I need
//"12.34" --> (12.34)*100 --> 1234
item.DECIMAL_VALUE = decimal.Parse(view.decimal_value) * 100;
I checked in debug mode: the value into item.DECIMAL_VALUE
is effectively a decimal and its value is 1234
(as expected).
Going on with the code I come to the point where I need to save the value into the database
_context.TABLE.Add(item);
return _context.SaveChanges();
And that's the problem. I get a DbUpdateException because it tries to save 1234,00
(which doesn't correspond to the decimal(4,0)
) instead of 1234
Any ideas on why it's doing it and how to solve?