Class QuantityFormatter


  • public class QuantityFormatter
    extends java.lang.Object
    A set of utility functions to use when formatting quantities
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatNumber​(double number)
      Formats a number to be comma delimited.
      static java.lang.String formatNumber​(long number)
      Formats a number to be comma delimited.
      static long parseQuantity​(java.lang.String string)
      Converts a string representation of a stack back to (close to) it's original value.
      static java.lang.String quantityToRSDecimalStack​(int quantity)
      Convert a quantity to a short SI-prefix style string, possibly with a decimal, with K after 100,000 and M after 10,000,000 example: 9,450, 2.1B, 100K
      static java.lang.String quantityToRSDecimalStack​(int quantity, boolean precise)
      Convert a quantity to a short SI-prefix style string, possibly with decimals, with K after 100,000 and M after 10,000,000 example without precise: 9,450, 2.1B, 8.4M example with precise: 9,450, 2.147B, 8.32M
      static java.lang.String quantityToStackSize​(long quantity)
      Convert a quantity to a short, comma separated, SI-prefix style string example: 9,450, 2.14B, 100K
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • QuantityFormatter

        public QuantityFormatter()
    • Method Detail

      • quantityToStackSize

        public static java.lang.String quantityToStackSize​(long quantity)
        Convert a quantity to a short, comma separated, SI-prefix style string example: 9,450, 2.14B, 100K
        Parameters:
        quantity - The quantity to convert.
        Returns:
        a 6 or less character string, possibly with a decimal point, commas or K/M/B suffix
      • quantityToRSDecimalStack

        public static java.lang.String quantityToRSDecimalStack​(int quantity)
        Convert a quantity to a short SI-prefix style string, possibly with a decimal, with K after 100,000 and M after 10,000,000 example: 9,450, 2.1B, 100K
        See Also:
        quantityToRSDecimalStack(int, boolean)
      • quantityToRSDecimalStack

        public static java.lang.String quantityToRSDecimalStack​(int quantity,
                                                                boolean precise)
        Convert a quantity to a short SI-prefix style string, possibly with decimals, with K after 100,000 and M after 10,000,000 example without precise: 9,450, 2.1B, 8.4M example with precise: 9,450, 2.147B, 8.32M
        Parameters:
        precise - If true, allow thousandths precision if quantity is larger than 1 million. Otherwise have at most a single decimal
      • parseQuantity

        public static long parseQuantity​(java.lang.String string)
                                  throws java.text.ParseException
        Converts a string representation of a stack back to (close to) it's original value.
        Parameters:
        string - The string to convert.
        Returns:
        A long representation of it.
        Throws:
        java.text.ParseException
      • formatNumber

        public static java.lang.String formatNumber​(long number)
        Formats a number to be comma delimited. No suffixes are given example: 10,123,351, 5
      • formatNumber

        public static java.lang.String formatNumber​(double number)
        Formats a number to be comma delimited. No suffixes are given. Has at most 3 decimal places example: 10,123,351, 5.612