@Test public void testFormatLong() { assertThat(NumberUtils.format(-100), is("-100")); assertThat(NumberUtils.format(0), is("0")); assertThat(NumberUtils.format(100), is("100")); assertThat(NumberUtils.format(1000), is("1,000")); assertThat(NumberUtils.format(1000000000), is("1,000,000,000")); }
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);  }