/// <summary> /// 金額轉國字 /// </summary> /// <param name="amount"></param> /// <param name="amountUnit"></param> /// <returns></returns> public static string AmountToString(long amount, AmountUnit amountUnit) { int length = amount.ToString().Length - 1; if (amount < 0) { throw new ArgumentOutOfRangeException("amount", "數值必須為正整數"); } else if (length > 13) { throw new ArgumentOutOfRangeException("amount", "數值不可超過13位數"); } if (amountUnit == 0 || length > (int)amountUnit) { amountUnit = (AmountUnit)length; } string[] numberTexts = { "零", "壹", "貳", "參", "肆", "伍", "陸", "柒", "捌", "玖" }; string[] typeMappings = { "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟", "兆" }; long pow10, tempNum; List <string> result = new List <string>(); for (int i = (int)amountUnit; i >= 0; i--) { pow10 = Convert.ToInt64(Math.Pow(10, i)); tempNum = amount / pow10; amount -= tempNum * pow10; result.Add(numberTexts[tempNum]); if (typeMappings[i] != "") { result.Add(typeMappings[i]); } } return(string.Join(" ", result)); }
public void Apply(Order order) { var amountUnit = AmountUnit.ToDomainModel <AmountUnit>(); order.AddItem( ProductUnit.Of( Products.ProductId.From(ProductId), amountUnit), Products.Amount.Of( Amount, amountUnit)); }
public void CalculateProductPrice_ProductWithValidProps_ReturnsProductWithCalculatedPrice() { var calc = new PriceCalculator(); var kgAmount = new AmountUnit() { Id = 2, Name = "kg" }; var prodInParam = new Product() { Id = 2, Name = "Sugar", CategoryId = 1, MarketId = 1, OriginId = 1, PricePerUnit = 7.30, Amount = 2, AmountUnit = kgAmount, AmountUnitId = 2, }; var expectedProduct = new Product() { Id = 2, Name = "Sugar", CategoryId = 1, MarketId = 1, OriginId = 1, PricePerUnit = 7.30, Amount = 2, AmountUnit = kgAmount, AmountUnitId = 2, Price = 14.60, // calculated price }; var result = calc.CalculatePrice(prodInParam); result.Price.Should().Be(expectedProduct.Price); }
private Amount(float count, AmountUnit unit) { Unit = unit; Count = count < 0 ? 0 : count; }
public static IAmount Create(float count, AmountUnit unit) { return(new Amount(count, unit)); }
public static IAmount Zero(AmountUnit unit) { return(new Amount(0, unit)); }
public PurchaseAmount(double digit, AmountUnit amountUnit) { this._digit = digit; this._amountUnit = amountUnit; }
public static ProductAmount Of(ProductId productId, int value, AmountUnit unit) => new ProductAmount(productId, Amount.Of(value, unit));
private Amount(int value, AmountUnit unit) { Value = value; Unit = unit; }
public static Amount Of(int value, AmountUnit unit) => new Amount(value, unit);
private ProductUnit(ProductId productId, AmountUnit unit) { ProductId = productId; Unit = unit; }
public static ProductUnit Of(ProductId productId, AmountUnit unit) => new ProductUnit(productId, unit);