private void BuildCentPart(string centPart, IFluentDollarMoney centMoney) { if (centPart.Length > 2) { throw new ArgumentOutOfRangeException("Cent part cannot be greater than 99"); } if (centPart.Length == 2 && centPart[0] == '0') { centPart = centPart[1].ToString(); } else if (centPart.Length == 1) { centPart += "0"; } centMoney.WithCentValue(centPart); }
private void BuildDollarPart(string dollarPart, IFluentDollarMoney dollarMoney) { if (int.Parse(dollarPart) > 1000000000 || int.Parse(dollarPart) < 0) { throw new ArgumentOutOfRangeException("Dollar value out of range!"); } var moneySeparatorInterval = 3; var iterator = 0; var dollarIndex = dollarPart.Length; var hasNextDollarPart = true; while (hasNextDollarPart) { dollarIndex -= moneySeparatorInterval; hasNextDollarPart = TryGetNextDollarPart(ref dollarIndex, ref moneySeparatorInterval); var nextDollarPartValue = dollarPart.Substring(dollarIndex, moneySeparatorInterval); var nextDollarPart = (DollarParts)iterator; switch (nextDollarPart) { case DollarParts.Hundred: dollarMoney.WithHundredValue(nextDollarPartValue); break; case DollarParts.Thousand: dollarMoney.WithThousandValue(nextDollarPartValue); break; case DollarParts.Million: dollarMoney.WithMillionValue(nextDollarPartValue); break; default: throw new ArgumentOutOfRangeException($"Invalid {0} value!", nextDollarPart.ToString()); } iterator++; } }