2 ms·
This is a missunderstanding. If we have for example USD 10.42, the values in my implementation are: FinerAmount = 1042 CoarserAmount = 10.42 The profi
by Archelaos 5y ago
This is a missunderstanding.
If we have for example USD 10.42, the values in my implementation are:
FinerAmount = 1042
CoarserAmount = 10.42
The profile of the class was abbreviated. Of course, we also need a currency property for the general case:
Currency = USDollar
The definition of the class for the currency in pseudo-code:
class Iso4217CurrencyCode
int NumericCode
string AlphabeticCode
int DecimalPlaces
static USDollar = new Iso4217CurrencyCode(840, "USD", 2);
static Yen = new Iso4217CurrencyCode(392, "JPY", 0);
The constructor for the amount of money only uses FinerAmount, and CoarserAmount is calculated:
CoarserAmount => Convert.ToDecimal(FinerAmount / Math.Pow(10, Currency.DecimalPlaces));
So
foo = AmountOfMoney(FinerAmount: 1042, Currency: USDollar);
sets foo.CoarserAmount automatically to 10.42.
But
bar = AmountOfMoney(FinerAmount: 1042, Currency: Yen);
sets bar.CoarserAmount automatically to 1042.