### Question:
NumberFormats { public static NumberFormat format(int precision) { NumberFormat format = precisionFormat.get(precision); if (format == null) { precisionFormat.put(precision, createFormatter(precision)); } return precisionFormat.get(precision); } private  NumberFormats(); static NumberFormat format(int precision); static NumberFormat toStringFormat();  }### Answer:
@Test public void format1() { NumberFormat format = NumberFormats.format(2); assertThat(format.format(2.0), equalTo("2.00")); assertThat(format.format(Double.NaN), equalTo("NaN")); assertThat(format.format(Double.POSITIVE_INFINITY), equalTo("Infinity")); assertThat(format.format(Double.NEGATIVE_INFINITY), equalTo("-Infinity")); assertThat(NumberFormats.format(2), sameInstance(format)); }
@Test public void format2() { NumberFormat f = NumberFormats.format(3); assertThat(f.format(1234.4567), equalTo("1234.457")); assertThat(f.format(123), equalTo("123.000")); assertThat(f.format(123.4), equalTo("123.400")); f = NumberFormats.format(0); assertThat(f.format(1234.4567), equalTo("1234")); assertThat(f.format(123), equalTo("123")); assertThat(f.format(123.4), equalTo("123")); f = NumberFormats.format(4); assertThat(f.format(1234.4567), equalTo("1234.4567")); assertThat(f.format(123), equalTo("123.0000")); assertThat(f.format(123.4), equalTo("123.4000")); }