Package com.complexible.common.base
Class Numbers
- java.lang.Object
-
- com.complexible.common.base.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 longBILLIONConstant field for billion.static longKShort-name constant field for thousand (1000).static longMShort-name constant field for million.static longMILLIONConstant field for million.static longTHOUSANDConstant field for thousand.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringformatIfIntegral(java.lang.Object number)Formats the given number to a string with decimal separators if it is an integral number (Long,Integer,ShortorByte).static java.lang.StringformatWithSeparator(long number)Formats the given number to a string with decimal separators.static java.lang.NumberfromReadable(java.lang.String theStr)The opposite ofreadable(long): parses a readable string and returns the corresponding number.static booleanisNaN(java.lang.Number value)static java.lang.Stringreadable(double number)static java.lang.Stringreadable(long number)Always use US locale @see Numbers#readable(Locale, long)static java.lang.Stringreadable(java.util.Locale l, double number)static java.lang.Stringreadable(java.util.Locale l, long number)Returns a human-readable representation of numbers.static java.lang.NumbervalueOf(double value)static java.lang.NumbervalueOf(long value)Return anIntegerif given value long is less thanInteger.MAX_VALUEor aLongotherwise.
-
-
-
Field Detail
-
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 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 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
public static java.lang.Number fromReadable(java.lang.String theStr)
The opposite ofreadable(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 anIntegerif given value long is less thanInteger.MAX_VALUEor aLongotherwise.
-
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,ShortorByte). Equivalent to usingString#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 usingString#format("%,d", number).- Parameters:
number- number to format- Returns:
- formatted String
-
-