@Test
public void btcRounding() throws Exception {

    assertEquals("0", format(ZERO, 0, 0));
    assertEquals("0.00", format(ZERO, 0, 2));
    assertEquals("1", format(COIN, 0, 0));
    assertEquals("1.0", format(COIN, 0, 1));
    assertEquals("1.00", format(COIN, 0, 2, 2));
    assertEquals("1.00", format(COIN, 0, 2, 2, 2));
    assertEquals("1.00", format(COIN, 0, 2, 2, 2, 2));
    assertEquals("1.000", format(COIN, 0, 3));
    assertEquals("1.0000", format(COIN, 0, 4));
    final Coin justNot = COIN.subtract(SATOSHI);
    assertEquals("1", format(justNot, 0, 0));
    assertEquals("1.0", format(justNot, 0, 1));
    assertEquals("1.00", format(justNot, 0, 2, 2));
    assertEquals("1.00", format(justNot, 0, 2, 2, 2));
    assertEquals("0.99999999", format(justNot, 0, 2, 2, 2, 2));
    assertEquals("1.000", format(justNot, 0, 3));
    assertEquals("1.0000", format(justNot, 0, 4));
    final Coin slightlyMore = COIN.add(SATOSHI);
    assertEquals("1", format(slightlyMore, 0, 0));
    assertEquals("1.0", format(slightlyMore, 0, 1));
    assertEquals("1.00", format(slightlyMore, 0, 2, 2));
    assertEquals("1.00", format(slightlyMore, 0, 2, 2, 2));
    assertEquals("1.00000001", format(slightlyMore, 0, 2, 2, 2, 2));
    assertEquals("1.000", format(slightlyMore, 0, 3));
    assertEquals("1.0000", format(slightlyMore, 0, 4));
    final Coin pivot = COIN.add(SATOSHI.multiply(5));
    assertEquals("1.00000005", format(pivot, 0, 8));
    assertEquals("1.00000005", format(pivot, 0, 7, 1));
    assertEquals("1.0000001", format(pivot, 0, 7));
    final Coin value = Coin.valueOf(1122334455667788l);
    assertEquals("11223345", format(value, 0, 0));
    assertEquals("11223344.6", format(value, 0, 1));
    assertEquals("11223344.5567", format(value, 0, 2, 2));
    assertEquals("11223344.556678", format(value, 0, 2, 2, 2));
    assertEquals("11223344.55667788", format(value, 0, 2, 2, 2, 2));
    assertEquals("11223344.557", format(value, 0, 3));
    assertEquals("11223344.5567", format(value, 0, 4));
}