//------------------------------------------------------------------------- public virtual void test_amount() { assertEquals(SummarizerUtils.amount(amount(GBP, 12.34)), "GBP 12.34"); assertEquals(SummarizerUtils.amount(GBP, 12.34), "GBP 12.34"); assertEquals(SummarizerUtils.amount(GBP, 123), "GBP 123"); assertEquals(SummarizerUtils.amount(GBP, 1230), "GBP 1,230"); assertEquals(SummarizerUtils.amount(GBP, 12300), "GBP 12,300"); assertEquals(SummarizerUtils.amount(GBP, 123000), "GBP 123k"); assertEquals(SummarizerUtils.amount(GBP, 1230000), "GBP 1.23mm"); }
/// <summary> /// Converts an FX exchange to a string. /// </summary> /// <param name="base"> the base currency amount </param> /// <param name="counter"> the counter currency amount </param> /// <returns> the string form </returns> public static string fx(CurrencyAmount @base, CurrencyAmount counter) { decimal rateDec = decimal.valueOf(counter.Amount / @base.Amount).setScale(@base.Currency.MinorUnitDigits + 2, RoundingMode.HALF_UP).abs(); FxRate rate = FxRate.of(@base.Currency, counter.Currency, rateDec.doubleValue()); decimal baseDec = decimal.valueOf(@base.Amount).stripTrailingZeros(); decimal counterDec = decimal.valueOf(counter.Amount).stripTrailingZeros(); bool roundBase = baseDec.scale() < counterDec.scale(); CurrencyAmount round = roundBase ? @base : counter; return((round.Amount < 0 ? "Pay " : "Rec ") + SummarizerUtils.amount(round.mapAmount(a => Math.Abs(a))) + " " + "@ " + rate); }