Reputation: 49
I am trying to read values from excel sheet cells, where I find values like 123,10000. So there are always 5 decimal places. Now, I read in this value from a cell like this:
reportedAmount = _converter.ToDecimalOrZero(row[25].ToString());
The ToDecimalOrZero
method looks like this:
internal decimal ToDecimalOrZero(string v)
{
String formattedDecimalInput = String.Format("{0:0.00000}", v);
try
{
return Convert.ToDecimal(formattedDecimalInput);
}
catch
{
return Convert.ToDecimal(String.Format("{0:0.00000}", 0));
}
}
Now, the issue is that the returned values will always have no trailing zeroes, regardless of how the input is. What I notice when doing some simple debugging is that the method that reads out the value from a cell is the one that removes the zeroes. However, what is confusing to me is that String.Format("{0:0.00000}", v)
does not return the value with 5 decimal places, but returns the same format that the value we gave to it had (the one without trailing zeroes). Any ideas? Thank you.
Upvotes: 1
Views: 138