In C# / .NET, how to parse a decimal out of a currency amount stored in a
string, and NOT lose precision or do rounding?
I have code like
private static decimal ParseAmountFrom(string amount)
{
decimal amount;
if (!Decimal.TryParse(amount, NumberStyles.Currency,
CultureInfo.InvariantCulture, out amount))
{
throw new AmountNotADecimalException(unParsed.Amount);
}
return amount;
}
If I call ParseAmountFrom("234.256") I get back a value 234.25m. I've lost
the 0.006.
How can I parse the strings so no precision is lost, and no rounding occurs?
No comments:
Post a Comment