DecimalType extends Number implements PrimitiveType, State, Command, Comparable<DecimalType> { @Override public String format(String pattern) { try { return String.format(pattern, value.toBigIntegerExact()); } catch (ArithmeticException ae) { } catch (IllegalFormatConversionException ifce) { } return String.format(pattern, value); } DecimalType();  DecimalType(BigDecimal value);  DecimalType(long value);  DecimalType(double value);  DecimalType(String value); @Override String toString(); @Override String toFullString(); static DecimalType valueOf(String value); @Override String format(String pattern); BigDecimal toBigDecimal(); @Override int hashCode(); @Override boolean equals(@Nullable Object obj); @Override int compareTo(DecimalType o); @Override double doubleValue(); @Override float floatValue(); @Override int intValue(); @Override long longValue(); @Override T as(@Nullable Class<T> target); static final DecimalType ZERO; }
@Test public void testIntFormat() { DecimalType dt; dt = new DecimalType("87"); assertEquals("87", dt.format("%d")); dt = new DecimalType("87"); assertEquals(" 87", dt.format("%3d")); dt = new DecimalType("87"); assertEquals("0x57", dt.format("%#x")); dt = new DecimalType("87.5"); try { dt.format("%x"); fail(); } catch (Exception e) { } dt = new DecimalType("11.0"); assertEquals("11", dt.format("%d")); }
@Test public void testFloatFormat() { DecimalType dt; final char sep = (new DecimalFormatSymbols().getDecimalSeparator()); dt = new DecimalType("11.123"); assertEquals("11" + sep + "1", dt.format("%.1f")); dt = new DecimalType("11"); assertEquals("11" + sep + "0", dt.format("%.1f")); dt = new DecimalType("11.0"); assertEquals("11" + sep + "0", dt.format("%.1f")); }