Is it possible to use system.currency. It says system.currency is inaccessible due to its protection level. what is the alternative of currency.
You have to use Decimal data type..
The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.
It may be possible via reflection but the reasons that it's there are for FromOACurrency()
and ToOACurrency()
static methods on System.Decimal
, which is for convering from/to the Ole Automation Currency
type that Visual Basic 6 uses.
Use Decimal. All of the functions that Currency provides are static methods on Decimal, FromOACurrency, and ToOACurrency.
You can't actually use Decimal for Currency. You'll face bigger problems later on when you divide. Say if you have $1 split into 3 which is 1/3 = 0.33(rounded), but 3 x 0.33 = 0.99 != 1. It might be small, but when you do that in accounting ans stack up your sheets, it will be a huge figure. Also that's why the default rounding up/down behavior in .Net (not sure about other programming languages) is to the next even value, also called bankers' rounding, to minimized error in accounting comparing to our normal "human" way of rounding.
Read this page for clearer explanation and a special class to handle money. Code Project : A Money type for the CLR
Also about Rounding