QuantityFormatter { public static synchronized long parseQuantity(String string) throws ParseException { int multiplier = getMultiplier(string); float parsedValue = NUMBER_FORMATTER.parse(string).floatValue(); return (long) (parsedValue * multiplier); }  static synchronized String quantityToStackSize(long quantity); static String quantityToRSDecimalStack(int quantity); static synchronized String quantityToRSDecimalStack(int quantity, boolean precise); static synchronized long parseQuantity(String string); static synchronized String formatNumber(final long number); static synchronized String formatNumber(double number);  }
@Test public void stackSizeToQuantity() throws ParseException { assertEquals(0, QuantityFormatter.parseQuantity("0")); assertEquals(907, QuantityFormatter.parseQuantity("907")); assertEquals(1200, QuantityFormatter.parseQuantity("1200")); assertEquals(10_500, QuantityFormatter.parseQuantity("10,500")); assertEquals(10_500, QuantityFormatter.parseQuantity("10.5K")); assertEquals(33_560_000, QuantityFormatter.parseQuantity("33.56M")); assertEquals(2_000_000_000, QuantityFormatter.parseQuantity("2B")); assertEquals(0, QuantityFormatter.parseQuantity("-0")); assertEquals(-400, QuantityFormatter.parseQuantity("-400")); assertEquals(-400_000, QuantityFormatter.parseQuantity("-400k")); assertEquals(-40_543_000, QuantityFormatter.parseQuantity("-40.543M")); try { QuantityFormatter.parseQuantity("0L"); fail("Should have thrown an exception for invalid suffix."); } catch (ParseException ignore) { } try { QuantityFormatter.parseQuantity("badstack"); fail("Should have thrown an exception for improperly formatted stack."); } catch (ParseException ignore) { } }