@Test public void testFormatDouble() { assertThat(NumberUtils.format(-100, 2), is("-100.00")); assertThat(NumberUtils.format(0, 0), is("0")); assertThat(NumberUtils.format(0, 2), is("0.00")); assertThat(NumberUtils.format(100.0, 0), is("100")); assertThat(NumberUtils.format(100.6, 0), is("101")); assertThat(NumberUtils.format(100.1, 2), is("100.10")); assertThat(NumberUtils.format(10.1234, 2), is("10.12")); assertThat(NumberUtils.format(10.1234, 4), is("10.1234")); assertThat(NumberUtils.format(1000.123, 2), is("1,000.12")); assertThat(NumberUtils.format(1000.126, 2), is("1,000.13")); }
public static String format(final long value) { boolean negative = value < 0; final String num = String.valueOf(Math.abs(value)); String formattedNum = ""; for (int i = num.length() - 1, j = 0; i >= 0; i--, j++) { formattedNum += num.charAt(j); if (i % 3 == 0 && i != 0) { formattedNum += ","; } } return negative ? "-" + formattedNum : formattedNum; }
NumberUtils { public static String format(final long value) { boolean negative = value < 0; final String num = String.valueOf(Math.abs(value)); String formattedNum = ""; for (int i = num.length() - 1, j = 0; i >= 0; i--, j++) { formattedNum += num.charAt(j); if (i % 3 == 0 && i != 0) { formattedNum += ","; } } return negative ? "-" + formattedNum : formattedNum; } }
NumberUtils { public static String format(final long value) { boolean negative = value < 0; final String num = String.valueOf(Math.abs(value)); String formattedNum = ""; for (int i = num.length() - 1, j = 0; i >= 0; i--, j++) { formattedNum += num.charAt(j); if (i % 3 == 0 && i != 0) { formattedNum += ","; } } return negative ? "-" + formattedNum : formattedNum; }  }
NumberUtils { public static String format(final long value) { boolean negative = value < 0; final String num = String.valueOf(Math.abs(value)); String formattedNum = ""; for (int i = num.length() - 1, j = 0; i >= 0; i--, j++) { formattedNum += num.charAt(j); if (i % 3 == 0 && i != 0) { formattedNum += ","; } } return negative ? "-" + formattedNum : formattedNum; }  static double parse(String value, int decimalPlaces); static String format(final long value); static String format(double value, int decimalPlaces); }
NumberUtils { public static String format(final long value) { boolean negative = value < 0; final String num = String.valueOf(Math.abs(value)); String formattedNum = ""; for (int i = num.length() - 1, j = 0; i >= 0; i--, j++) { formattedNum += num.charAt(j); if (i % 3 == 0 && i != 0) { formattedNum += ","; } } return negative ? "-" + formattedNum : formattedNum; }  static double parse(String value, int decimalPlaces); static String format(final long value); static String format(double value, int decimalPlaces);  }