org.apache.commons.lang
public final class NumberUtils extends Object
Deprecated: Moved to org.apache.commons.lang.math. Class will be removed in Commons Lang 3.0.
Provides extra functionality for Java Number classes.
Since: 1.0
Version: $Id: NumberUtils.java 488819 2006-12-19 21:50:04Z bayard $
| Constructor Summary | |
|---|---|
| NumberUtils()
| |
| Method Summary | |
|---|---|
| static int | compare(double lhs, double rhs) Compares two This method is more comprehensive than the standard Java greater than, less than and equals operators.
|
| static int | compare(float lhs, float rhs) Compares two floats for order. This method is more comprehensive than the standard Java greater than, less than and equals operators.
|
| static BigDecimal | createBigDecimal(String val) Convert a |
| static BigInteger | createBigInteger(String val) Convert a |
| static Double | createDouble(String val) Convert a |
| static Float | createFloat(String val) Convert a |
| static Integer | createInteger(String val) Convert a |
| static Long | createLong(String val) Convert a |
| static Number | createNumber(String val) Turns a string value into a java.lang.Number. First, the value is examined for a type qualifier on the end
( |
| static boolean | isDigits(String str) Checks whether the
|
| static boolean | isNumber(String str) Checks whether the String a valid Java number. Valid numbers include hexadecimal marked with the |
| static long | maximum(long a, long b, long c) Gets the maximum of three |
| static int | maximum(int a, int b, int c) Gets the maximum of three |
| static long | minimum(long a, long b, long c) Gets the minimum of three |
| static int | minimum(int a, int b, int c) Gets the minimum of three |
| static int | stringToInt(String str) Convert a |
| static int | stringToInt(String str, int defaultValue) Convert a |
NumberUtils instances should NOT be constructed in standard programming.
Instead, the class should be used as NumberUtils.stringToInt("6");.
This constructor is public to permit tools that require a JavaBean instance to operate.
Compares two doubles for order.
This method is more comprehensive than the standard Java greater than, less than and equals operators.
-1 if the first value is less than the second.
+1 if the first value is greater than the second.
0 if the values are equal.
The ordering is as follows, largest to smallest:
Comparing NaN with NaN will
return 0.
Parameters: lhs the first double rhs the second double
Returns: -1 if lhs is less, +1 if greater,
0 if equal to rhs
Compares two floats for order.
This method is more comprehensive than the standard Java greater than, less than and equals operators.
-1 if the first value is less than the second.
+1 if the first value is greater than the second.
0 if the values are equal.
The ordering is as follows, largest to smallest:
Comparing NaN with NaN will return
0.
Parameters: lhs the first float rhs the second float
Returns: -1 if lhs is less, +1 if greater,
0 if equal to rhs
Convert a String to a BigDecimal.
Parameters: val a String to convert
Returns: converted BigDecimal
Throws: NumberFormatException if the value cannot be converted
Convert a String to a BigInteger.
Parameters: val a String to convert
Returns: converted BigInteger
Throws: NumberFormatException if the value cannot be converted
Convert a String to a Double.
Parameters: val a String to convert
Returns: converted Double
Throws: NumberFormatException if the value cannot be converted
Convert a String to a Float.
Parameters: val a String to convert
Returns: converted Float
Throws: NumberFormatException if the value cannot be converted
Convert a String to a Integer, handling
hex and octal notations.
Parameters: val a String to convert
Returns: converted Integer
Throws: NumberFormatException if the value cannot be converted
Convert a String to a Long.
Parameters: val a String to convert
Returns: converted Long
Throws: NumberFormatException if the value cannot be converted
Turns a string value into a java.lang.Number.
First, the value is examined for a type qualifier on the end
('f','F','d','D','l','L'). If it is found, it starts
trying to create successively larger types from the type specified
until one is found that can hold the value.
If a type specifier is not found, it will check for a decimal point
and then try successively larger types from Integer to
BigInteger and from Float to
BigDecimal.
If the string starts with 0x or -0x, it
will be interpreted as a hexadecimal integer. Values with leading
0's will not be interpreted as octal.
Parameters: val String containing a number
Returns: Number created from the string
Throws: NumberFormatException if the value cannot be converted
Checks whether the String contains only
digit characters.
Null and empty String will return
false.
Parameters: str the String to check
Returns: true if str contains only unicode numeric
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x
qualifier, scientific notation and numbers marked with a type
qualifier (e.g. 123L).
Null and empty String will return
false.
Parameters: str the String to check
Returns: true if the string is a correctly formatted number
Gets the maximum of three long values.
Parameters: a value 1 b value 2 c value 3
Returns: the largest of the values
Gets the maximum of three int values.
Parameters: a value 1 b value 2 c value 3
Returns: the largest of the values
Gets the minimum of three long values.
Parameters: a value 1 b value 2 c value 3
Returns: the smallest of the values
Gets the minimum of three int values.
Parameters: a value 1 b value 2 c value 3
Returns: the smallest of the values
Convert a String to an int, returning
zero if the conversion fails.
Parameters: str the string to convert
Returns: the int represented by the string, or zero if
conversion fails
Convert a String to an int, returning a
default value if the conversion fails.
Parameters: str the string to convert defaultValue the default value
Returns: the int represented by the string, or the default if conversion fails