NumberUtils { public static String format(Object value) { if (value == null) { return null; } if (value instanceof BigDecimal) { value = String.format("%.2f", (BigDecimal) value); } else if (value instanceof Double) { value = String.format("%.2f", (Double) value); } else if (value instanceof Float) { value = String.format("%.2f", (Float) value); } return value.toString(); } private  NumberUtils(); static String format(Object value); static boolean isDouble(Class<?> clazz); static boolean isDouble(Object value); static boolean isFloat(Class<?> clazz); static boolean isInteger(Class<?> clazz); static boolean isInteger(Object value); static boolean isLong(Class<?> clazz); static boolean isLong(Object value); static boolean isNumeric(Class<?> clazz);  }
@Test public void testFormat() { assertEquals("Test", NumberUtils.format("Test")); assertEquals("1234", NumberUtils.format(1234L)); assertEquals(formatNumber("4,45"), NumberUtils.format(4.45)); assertEquals(formatNumber("4,23"), NumberUtils.format(BigDecimal.valueOf(4.23))); assertEquals(formatNumber("2,04"), NumberUtils.format(2.04f)); }