Package com.complexible.common.base

# 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 Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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`).
  `static String`
  `formatWithSeparator(long number)`
  Formats the given number to a string with decimal separators.
  `static Number`
  `fromReadable(String theStr)`
  The opposite of `readable(long)`: parses a readable string and returns the corresponding number.
  `static boolean`
  `isNaN(Number value)`
  `static String`
  `readable(double number)`
  `static String`
  `readable(long number)`
  Always use US locale @see Numbers#readable(Locale, long)
  `static String`
  `readable(Locale l, double number)`
  `static String`
  `readable(Locale l, long number)`
  Returns a human-readable representation of numbers.
  `static Number`
  `valueOf(double value)`
  `static 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`

- ## Field Details

  - ### THOUSAND

    public static final long THOUSAND
    Constant field for thousand.
    See Also:
      - Constant Field Values

  - ### K

    public static final long K
    Short-name constant field for thousand (1000).
    See Also:
      - Constant Field Values

  - ### MILLION

    public static final long MILLION
    Constant field for million.
    See Also:
      - Constant Field Values

  - ### M

    public static final long M
    Short-name constant field for million.
    See Also:
      - Constant Field Values

  - ### BILLION

    public static final long BILLION
    Constant field for billion.
    See Also:
      - Constant Field Values

- ## 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