Class Numbers


  • public final class Numbers
    extends java.lang.Object
    Since:
    2.0
    Version:
    2.0
    Author:
    Evren Sirin
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long BILLION
      Constant field for billion.
      static long K
      Short-name constant field for thousand (1000).
      static long M
      Short-name constant field for million.
      static long MILLION
      Constant field for million.
      static long THOUSAND
      Constant field for thousand.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String formatIfIntegral​(java.lang.Object number)
      Formats the given number to a string with decimal separators if it is an integral number (Long, Integer, Short or Byte).
      static java.lang.String formatWithSeparator​(long number)
      Formats the given number to a string with decimal separators.
      static java.lang.Number fromReadable​(java.lang.String theStr)
      The opposite of readable(long): parses a readable string and returns the corresponding number.
      static boolean isNaN​(java.lang.Number value)  
      static java.lang.String readable​(double number)  
      static java.lang.String readable​(long number)
      Always use US locale @see Numbers#readable(Locale, long)
      static java.lang.String readable​(java.util.Locale l, double number)  
      static java.lang.String readable​(java.util.Locale l, long number)
      Returns a human-readable representation of numbers.
      static java.lang.Number valueOf​(double value)  
      static java.lang.Number valueOf​(long value)
      Return an Integer if given value long is less than Integer.MAX_VALUE or a Long otherwise.
      • Methods inherited from class java.lang.Object

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

      • readable

        public static java.lang.String readable​(long number)
        Always use US locale @see Numbers#readable(Locale, long)
      • readable

        public static java.lang.String readable​(java.util.Locale l,
                                                long number)
        Returns a human-readable representation of numbers. This function is similar to Memory.readable(long) in spirit but works with powers of 10 (not 2), supports only two suffixes ('K' for thousands and 'M' for millions), and always prints one fraction digit for numbers greater then 1M.
          500 = 500
          1000 = 1.0K
          6700 = 6.7K
          10000 = 10K
          17500 = 18K
          940000 = 940K
          1120000 = 1.1M
          4600000 = 4.6M
          12000000 = 12.0M
          130000000 = 130.0M
          1240000000 = 1240.0M
         
      • fromReadable

        public static java.lang.Number fromReadable​(java.lang.String theStr)
        The opposite of readable(long): parses a readable string and returns the corresponding number.
        Parameters:
        theStr - input string
        Returns:
        number represented by the string
      • readable

        public static java.lang.String readable​(double number)
      • readable

        public static java.lang.String readable​(java.util.Locale l,
                                                double number)
      • valueOf

        public static java.lang.Number valueOf​(long value)
        Return an Integer if given value long is less than Integer.MAX_VALUE or a Long otherwise.
      • valueOf

        public static java.lang.Number valueOf​(double value)
      • isNaN

        public static boolean isNaN​(java.lang.Number value)
      • formatIfIntegral

        public static java.lang.String formatIfIntegral​(java.lang.Object number)
        Formats the given number to a string with decimal separators if it is an integral number (Long, Integer, Short or Byte). Equivalent to using String#format("%,d", number).
        Parameters:
        number - number to format
        Returns:
        formatted String
      • formatWithSeparator

        public static java.lang.String formatWithSeparator​(long number)
        Formats the given number to a string with decimal separators. Equivalent to using String#format("%,d", number).
        Parameters:
        number - number to format
        Returns:
        formatted String