Percent implements Comparable<Percent> { @Override public String toString() { return percent + "%"; } Percent(String value);  Percent(int value);  Percent(double value); double getValue(); double getPercent(); @Override String toString(); String toString(int precision); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(Percent o); static final Percent ZERO; static final Percent HUNDRED; }
@Test public void testToString_Precision() { assertEquals("0.000124%", new Percent("0.0001237%").toString(3)); assertEquals("1.01%", new Percent("1.0111111%").toString(3)); assertEquals("1.012%", new Percent("1.011811%").toString(4)); assertEquals("1.0110000%", new Percent("1.011%").toString(8)); assertEquals("100.1%", new Percent("100.09%").toString(4)); }