Package com.complexible.common.base
Class Numbers
java.lang.Object
com.complexible.common.base.Numbers
- Since:
- 2.0
- Version:
- 2.0
- Author:
- Evren Sirin
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longConstant field for billion.static final longShort-name constant field for thousand (1000).static final longShort-name constant field for million.static final longConstant field for million.static final longConstant field for thousand. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringformatIfIntegral(Object number) Formats the given number to a string with decimal separators if it is an integral number (Long,Integer,ShortorByte).static StringformatWithSeparator(long number) Formats the given number to a string with decimal separators.static NumberfromReadable(String theStr) The opposite ofreadable(long): parses a readable string and returns the corresponding number.static booleanstatic Stringreadable(double number) static Stringreadable(long number) Always use US locale @see Numbers#readable(Locale, long)static Stringstatic StringReturns a human-readable representation of numbers.static NumbervalueOf(double value) static NumbervalueOf(long value)
-
Field Details
-
THOUSAND
public static final long THOUSANDConstant field for thousand.- See Also:
-
K
public static final long KShort-name constant field for thousand (1000).- See Also:
-
MILLION
public static final long MILLIONConstant field for million.- See Also:
-
M
public static final long MShort-name constant field for million.- See Also:
-
BILLION
public static final long BILLIONConstant field for billion.- See Also:
-
-
Method Details
-
readable
Always use US locale @see Numbers#readable(Locale, long) -
readable
Returns a human-readable representation of numbers. This function is similar toMemory.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
The opposite ofreadable(long): parses a readable string and returns the corresponding number.- Parameters:
theStr- input string- Returns:
- number represented by the string
-
readable
-
readable
-
valueOf
-
valueOf
-
isNaN
-
formatIfIntegral
Formats the given number to a string with decimal separators if it is an integral number (Long,Integer,ShortorByte). Equivalent to usingString#format("%,d", number).- Parameters:
number- number to format- Returns:
- formatted String
-
formatWithSeparator
Formats the given number to a string with decimal separators. Equivalent to usingString#format("%,d", number).- Parameters:
number- number to format- Returns:
- formatted String
-