### Question:
StackFormatter { public static String quantityToStackSize(long quantity) { if (quantity < 0) { return "-" + quantityToStackSize(quantity == Long.MIN_VALUE ? Long.MAX_VALUE : -quantity); } else if (quantity < 10_000) { return NUMBER_FORMATTER.format(quantity); } String suffix = SUFFIXES[0]; long divideBy = 1; for (int i = (SUFFIXES.length - 1); i >= 0; i--) { divideBy = (long) Math.pow(10, i * 3); if ((double) quantity / divideBy >= 1) { suffix = SUFFIXES[i]; break; } } String formattedString = NUMBER_FORMATTER.format((double) quantity / divideBy); formattedString = (formattedString.length() > 4 ? formattedString.substring(0, 4) : formattedString); return (formattedString.endsWith(".") ? formattedString.substring(0, 3) : formattedString) + suffix; }  static String quantityToStackSize(long quantity); static String quantityToRSStackSize(int quantity); static long stackSizeToQuantity(String string); static String formatNumber(final long number); static String formatNumber(double number);  }### Answer:
@Test public void quantityToStackSize() { assertEquals("0", StackFormatter.quantityToStackSize(0)); assertEquals("999", StackFormatter.quantityToStackSize(999)); assertEquals(NumberFormat.getIntegerInstance().format(1000), StackFormatter.quantityToStackSize(1000)); assertEquals(NumberFormat.getIntegerInstance().format(9450), StackFormatter.quantityToStackSize(9450)); assertEquals(NumberFormat.getNumberInstance().format(14.5) + "K", StackFormatter.quantityToStackSize(14_500)); assertEquals(NumberFormat.getNumberInstance().format(99.9) + "K", StackFormatter.quantityToStackSize(99_920)); assertEquals("100K", StackFormatter.quantityToStackSize(100_000)); assertEquals("10M", StackFormatter.quantityToStackSize(10_000_000)); assertEquals(NumberFormat.getNumberInstance().format(2.14) + "B", StackFormatter.quantityToStackSize(Integer.MAX_VALUE)); assertEquals("100B", StackFormatter.quantityToStackSize(100_000_000_000L)); assertEquals("0", StackFormatter.quantityToStackSize(-0)); assertEquals("-400", StackFormatter.quantityToStackSize(-400)); assertEquals("-400K", StackFormatter.quantityToStackSize(-400_000)); assertEquals("-40M", StackFormatter.quantityToStackSize(-40_000_000)); assertEquals(NumberFormat.getNumberInstance().format(-2.14) + "B", StackFormatter.quantityToStackSize(Integer.MIN_VALUE)); assertEquals("-400B", StackFormatter.quantityToStackSize(-400_000_000_000L)); }