Class NumberUtils
- java.lang.Object
 - 
- org.apache.commons.lang.NumberUtils
 
 
- 
public final class NumberUtils extends java.lang.ObjectDeprecated.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
 
 
- 
- 
Constructor Summary
Constructors Constructor Description NumberUtils()Deprecated.NumberUtilsinstances should NOT be constructed in standard programming. 
- 
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static intcompare(double lhs, double rhs)Deprecated.Compares twodoublesfor order.static intcompare(float lhs, float rhs)Deprecated.Compares two floats for order.static java.math.BigDecimalcreateBigDecimal(java.lang.String val)Deprecated.Convert aStringto aBigDecimal.static java.math.BigIntegercreateBigInteger(java.lang.String val)Deprecated.Convert aStringto aBigInteger.static java.lang.DoublecreateDouble(java.lang.String val)Deprecated.Convert aStringto aDouble.static java.lang.FloatcreateFloat(java.lang.String val)Deprecated.Convert aStringto aFloat.static java.lang.IntegercreateInteger(java.lang.String val)Deprecated.Convert aStringto aInteger, handling hex and octal notations.static java.lang.LongcreateLong(java.lang.String val)Deprecated.Convert aStringto aLong.static java.lang.NumbercreateNumber(java.lang.String val)Deprecated.Turns a string value into a java.lang.Number.static booleanisDigits(java.lang.String str)Deprecated.Checks whether theStringcontains only digit characters.static booleanisNumber(java.lang.String str)Deprecated.Checks whether the String a valid Java number.static intmaximum(int a, int b, int c)Deprecated.Gets the maximum of threeintvalues.static longmaximum(long a, long b, long c)Deprecated.Gets the maximum of threelongvalues.static intminimum(int a, int b, int c)Deprecated.Gets the minimum of threeintvalues.static longminimum(long a, long b, long c)Deprecated.Gets the minimum of threelongvalues.static intstringToInt(java.lang.String str)Deprecated.Convert aStringto anint, returningzeroif the conversion fails.static intstringToInt(java.lang.String str, int defaultValue)Deprecated.Convert aStringto anint, returning a default value if the conversion fails. 
 - 
 
- 
- 
Method Detail
- 
stringToInt
public static int stringToInt(java.lang.String str)
Deprecated.Convert a
Stringto anint, returningzeroif the conversion fails.- Parameters:
 str- the string to convert- Returns:
 - the int represented by the string, or 
zeroif conversion fails 
 
- 
stringToInt
public static int stringToInt(java.lang.String str, int defaultValue)Deprecated.Convert a
Stringto anint, returning a default value if the conversion fails.- Parameters:
 str- the string to convertdefaultValue- the default value- Returns:
 - the int represented by the string, or the default if conversion fails
 
 
- 
createNumber
public static java.lang.Number createNumber(java.lang.String val) throws java.lang.NumberFormatExceptionDeprecated.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
IntegertoBigIntegerand fromFloattoBigDecimal.If the string starts with
0xor-0x, it will be interpreted as a hexadecimal integer. Values with leading0's will not be interpreted as octal.- Parameters:
 val- String containing a number- Returns:
 - Number created from the string
 - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createFloat
public static java.lang.Float createFloat(java.lang.String val)
Deprecated.Convert a
Stringto aFloat.- Parameters:
 val- aStringto convert- Returns:
 - converted 
Float - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createDouble
public static java.lang.Double createDouble(java.lang.String val)
Deprecated.Convert a
Stringto aDouble.- Parameters:
 val- aStringto convert- Returns:
 - converted 
Double - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createInteger
public static java.lang.Integer createInteger(java.lang.String val)
Deprecated.Convert a
Stringto aInteger, handling hex and octal notations.- Parameters:
 val- aStringto convert- Returns:
 - converted 
Integer - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createLong
public static java.lang.Long createLong(java.lang.String val)
Deprecated.Convert a
Stringto aLong.- Parameters:
 val- aStringto convert- Returns:
 - converted 
Long - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createBigInteger
public static java.math.BigInteger createBigInteger(java.lang.String val)
Deprecated.Convert a
Stringto aBigInteger.- Parameters:
 val- aStringto convert- Returns:
 - converted 
BigInteger - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
createBigDecimal
public static java.math.BigDecimal createBigDecimal(java.lang.String val)
Deprecated.Convert a
Stringto aBigDecimal.- Parameters:
 val- aStringto convert- Returns:
 - converted 
BigDecimal - Throws:
 java.lang.NumberFormatException- if the value cannot be converted
 
- 
minimum
public static long minimum(long a, long b, long c)Deprecated.Gets the minimum of three
longvalues.- Parameters:
 a- value 1b- value 2c- value 3- Returns:
 - the smallest of the values
 
 
- 
minimum
public static int minimum(int a, int b, int c)Deprecated.Gets the minimum of three
intvalues.- Parameters:
 a- value 1b- value 2c- value 3- Returns:
 - the smallest of the values
 
 
- 
maximum
public static long maximum(long a, long b, long c)Deprecated.Gets the maximum of three
longvalues.- Parameters:
 a- value 1b- value 2c- value 3- Returns:
 - the largest of the values
 
 
- 
maximum
public static int maximum(int a, int b, int c)Deprecated.Gets the maximum of three
intvalues.- Parameters:
 a- value 1b- value 2c- value 3- Returns:
 - the largest of the values
 
 
- 
compare
public static int compare(double lhs, double rhs)Deprecated.Compares two
doublesfor order.This method is more comprehensive than the standard Java greater than, less than and equals operators.
- It returns 
-1if the first value is less than the second. - It returns 
+1if the first value is greater than the second. - It returns 
0if the values are equal. 
The ordering is as follows, largest to smallest:
- NaN
 - Positive infinity
 - Maximum double
 - Normal positive numbers
 - +0.0
 - -0.0
 - Normal negative numbers
 - Minimum double (-Double.MAX_VALUE)
 - Negative infinity
 
Comparing
NaNwithNaNwill return0.- Parameters:
 lhs- the firstdoublerhs- the seconddouble- Returns:
 -1if lhs is less,+1if greater,0if equal to rhs
 - It returns 
 
- 
compare
public static int compare(float lhs, float rhs)Deprecated.Compares two floats for order.
This method is more comprehensive than the standard Java greater than, less than and equals operators.
- It returns 
-1if the first value is less than the second. - It returns 
+1if the first value is greater than the second. - It returns 
0if the values are equal. 
The ordering is as follows, largest to smallest:
- NaN
 - Positive infinity
 - Maximum float
 - Normal positive numbers
 - +0.0
 - -0.0
 - Normal negative numbers
 - Minimum float (-Float.MAX_VALUE)
 - Negative infinity
 
Comparing
NaNwithNaNwill return0.- Parameters:
 lhs- the firstfloatrhs- the secondfloat- Returns:
 -1if lhs is less,+1if greater,0if equal to rhs
 - It returns 
 
- 
isDigits
public static boolean isDigits(java.lang.String str)
Deprecated.Checks whether the
Stringcontains only digit characters.Nulland empty String will returnfalse.- Parameters:
 str- theStringto check- Returns:
 trueif str contains only unicode numeric
 
- 
isNumber
public static boolean isNumber(java.lang.String str)
Deprecated.Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the
0xqualifier, scientific notation and numbers marked with a type qualifier (e.g. 123L).Nulland empty String will returnfalse.- Parameters:
 str- theStringto check- Returns:
 trueif the string is a correctly formatted number
 
 - 
 
 -