tags:

views:

709

answers:

4

Is it possible to use system.currency. It says system.currency is inaccessible due to its protection level. what is the alternative of currency.

+11  A: 

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.

Gulzar
You know, it's not "more precision" that is important, it's the type of precision. Decimal is based on a 10-base scale and will always exactly represent a decimal number within it's range. Floats types however are based on a binary scale and may be describing a fraction that is not part of base 10
nedruod
+2  A: 

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.

Mark Cidade
+7  A: 

Use Decimal. All of the functions that Currency provides are static methods on Decimal, FromOACurrency, and ToOACurrency.

MagicKat
+2  A: 

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

faulty