@Test
  public void testText() {
    assertEquals("1", one.toFormalString());
    assertEquals(0, new Decimal128("1", (short) 0).compareTo(one));
    assertEquals("2", two.toFormalString());
    assertEquals(0, new Decimal128("2", (short) 0).compareTo(two));
    assertEquals("0", zero.toFormalString());
    assertEquals(0, new Decimal128("0", (short) 0).compareTo(zero));

    assertEquals("1.000", new Decimal128(1L, (short) 3).toFormalString());
    assertEquals(0, new Decimal128("1", (short) 3).compareTo(one));

    assertEquals("2.000000", new Decimal128(2.0d, (short) 6).toFormalString());
    assertEquals("2.000", new Decimal128(2.0d, (short) 3).toFormalString());
    assertEquals(0, new Decimal128("2.0", (short) 6).compareTo(two));
    assertEquals(0, new Decimal128("2.0", (short) 3).compareTo(two));

    assertEquals("1.3330", new Decimal128("1.333", (short) 4).toFormalString());
    assertEquals("1.333000",
        new Decimal128("1.333", (short) 6).toFormalString());
    assertEquals("1.333", new Decimal128("1.333", (short) 3).toFormalString());
    assertEquals("1.33", new Decimal128("1.333", (short) 2).toFormalString());
    assertEquals("1.33", new Decimal128("1.333", (short) 2).toFormalString());

    assertEquals("0.13330",
        new Decimal128("1333E-4", (short) 5).toFormalString());
    assertEquals("0.01333",
        new Decimal128("1333E-5", (short) 5).toFormalString());
    assertEquals("13330000.00",
        new Decimal128("1333E4", (short) 2).toFormalString());

    assertEquals("123456789012345678901234.56789", new Decimal128(
        "123456789012345678901234567.8901234E-3", (short) 5).toFormalString());
  }
This code was based on code from Microsoft's PolyBase.
common/src/test/org/apache/hadoop/hive/common/type/TestDecimal128.java