public class NumberOps
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.Number |
intZero
Integer zero as a Number.
|
Constructor and Description |
---|
NumberOps() |
Modifier and Type | Method and Description |
---|---|
static java.lang.Number |
add(java.lang.Number number1,
java.lang.Number number2)
Add two numbers.
|
static java.lang.Number |
cloneNumber(java.lang.Number number)
Get copy of a Number object.
|
static int |
compareNumbers(java.lang.Number number1,
java.lang.Number number2)
Compare two numbers.
|
static int |
compareToZero(java.lang.Number number)
Compare a number to zero.
|
static java.lang.Number |
divide(java.lang.Number number1,
java.lang.Number number2)
Divide two numbers.
|
static java.lang.Number |
modulus(java.lang.Number number1,
java.lang.Number number2)
Find modulus of two numbers.
|
static java.lang.Number |
multiply(java.lang.Number number1,
java.lang.Number number2)
Multiply two numbers.
|
static java.lang.Number |
subtract(java.lang.Number number1,
java.lang.Number number2)
Substract two numbers.
|
static java.lang.Number |
toNumber(java.lang.String s)
Convert string to Number.
|
protected static final java.lang.Number intZero
public static int compareNumbers(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.public static int compareToZero(java.lang.Number number)
number
- Number to compare to zero.public static java.lang.Number add(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number subtract(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number multiply(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double.
public static java.lang.Number divide(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.If both number1 and number2 are Integers, the result is an Integer. Any other combination of Number types results in a Double. Zerodivides are passed through as NAN.
public static java.lang.Number modulus(java.lang.Number number1, java.lang.Number number2)
number1
- First number.number2
- Second number.The numbers are converted to Longs before performing the operation. The result is a Long. This gives the expected results if the numbers are both integral.
public static java.lang.Number toNumber(java.lang.String s) throws java.lang.NumberFormatException
s
- String to convert to Number.java.lang.NumberFormatException
- if "s" does not contain
a valid number.
If the string contains an integer, the resulting Number is an Integer. Anything other valid numeric string is converted to a Double. An invalid numeric string throws a NumberFormatException.
public static java.lang.Number cloneNumber(java.lang.Number number)
number
- The number object for which a copy is desired.This method exists because Java does not implement a proper clone method for the Number class.