Class Numbers

java.lang.Object
com.complexible.common.base.Numbers

public final class Numbers extends Object
Since:
2.0
Version:
2.0
Author:
Evren Sirin
  • Field Details

    • THOUSAND

      public static final long THOUSAND
      Constant field for thousand.
      See Also:
    • K

      public static final long K
      Short-name constant field for thousand (1000).
      See Also:
    • MILLION

      public static final long MILLION
      Constant field for million.
      See Also:
    • M

      public static final long M
      Short-name constant field for million.
      See Also:
    • BILLION

      public static final long BILLION
      Constant field for billion.
      See Also:
  • Method Details

    • readable

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

      public static String readable(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 Number fromReadable(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 String readable(double number)
    • readable

      public static String readable(Locale l, double number)
    • valueOf

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

      public static Number valueOf(double value)
    • isNaN

      public static boolean isNaN(Number value)
    • formatIfIntegral

      public static String formatIfIntegral(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 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