StringBuilderUtil { public static void format2f(@NonNull StringBuilder sb, float x) { final int x100 = Math.round(x * 100); final int whole = x100 / 100; final int tenths = x100 / 10 % 10; final int hundredths = x100 % 10; sb.append(whole); sb.append("."); sb.append(tenths); sb.append(hundredths); }  static void format2f(@NonNull StringBuilder sb, float x); static void format3f(@NonNull StringBuilder sb, double x); static void format2d(@NonNull StringBuilder sb, long x); static void format3d(@NonNull StringBuilder sb, long x);  }
@Test public void format2f() { StringBuilder sb = new StringBuilder(); for (float value : testFloats) { sb.setLength(0); StringBuilderUtil.format2f(sb, value); assertEquals(String.format("%.2f", value), sb.toString()); } }