public static synchronized String quantityToStackSize(long quantity)
	{
		if (quantity < 0)
		{
			// Long.MIN_VALUE = -1 * Long.MIN_VALUE so we need to correct for it.
			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;

		// determine correct suffix by iterating backward through the list
		// of suffixes until the suffix results in a value >= 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;
			}
		}

		// get locale formatted string
		String formattedString = NUMBER_FORMATTER.format((double) quantity / divideBy);

		// strip down any digits past the 4 first
		formattedString = (formattedString.length() > 4 ? formattedString.substring(0, 4) : formattedString);

		// make sure the last character is not a "."
		return (formattedString.endsWith(".") ? formattedString.substring(0, 3) : formattedString) + suffix;
	}
@Test
	public void quantityToStackSize()
	{
		assertEquals("0", QuantityFormatter.quantityToStackSize(0));
		assertEquals("999", QuantityFormatter.quantityToStackSize(999));
		assertEquals("1,000", QuantityFormatter.quantityToStackSize(1000));
		assertEquals("9,450", QuantityFormatter.quantityToStackSize(9450));
		assertEquals("14.5K", QuantityFormatter.quantityToStackSize(14_500));
		assertEquals("99.9K", QuantityFormatter.quantityToStackSize(99_920));
		assertEquals("100K", QuantityFormatter.quantityToStackSize(100_000));
		assertEquals("10M", QuantityFormatter.quantityToStackSize(10_000_000));
		assertEquals("2.14B", QuantityFormatter.quantityToStackSize(Integer.MAX_VALUE));
		assertEquals("100B", QuantityFormatter.quantityToStackSize(100_000_000_000L));

		assertEquals("0", QuantityFormatter.quantityToStackSize(-0));
		assertEquals("-400", QuantityFormatter.quantityToStackSize(-400));
		assertEquals("-400K", QuantityFormatter.quantityToStackSize(-400_000));
		assertEquals("-40M", QuantityFormatter.quantityToStackSize(-40_000_000));
		assertEquals("-2.14B", QuantityFormatter.quantityToStackSize(Integer.MIN_VALUE));
		assertEquals("-400B", QuantityFormatter.quantityToStackSize(-400_000_000_000L));
	}