Class next.util.DecimalNumber

CLASS DESCRIPTION

Extends:
next.util.NSNumber

DecimalNumber, an immutable subclass of NSNumber (which itself is a private class), provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa*10^exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer between -128 and 127.

In the course of doing arithmetic, a method may produce calculation errors, such as division by zero. It may also meet circumstances where it has a choice of ways to round a number off. The way the method acts on such occasions is called its "behavior." The arithmetic methods in this class do not round numbers off. They assume that your need for precision does not exceed 38 significant digits. And they raise exceptions when they try to divide by zero, or when they produce a number that is too big or small to be represented.


CONSTRUCTORS

DecimalNumber

static DecimalNumber()

Creates and returns a new DecimalNumber object.


DecimalNumber

public DecimalNumber()
public DecimalNumber(java.lang.String aString)
public DecimalNumber(long mantissa, int exponent)

Creates and returns a new DecimalNumber object. If aString is supplied, the new object is initialized using initWithString. If mantissa and exponent are supplied, the new object is initialized using initWithMantissaAndExponent.


METHODS

byAdding

public static next.util.DecimalNumber byAdding(next.util.DecimalNumber aDecimalNumber)

Adds aDecimalNumber to the receiver, and returns the sum, a newly created DecimalNumber.


byDividingBy

public static next.util.DecimalNumber byDividingBy(next.util.DecimalNumber aDecimalNumber)

Divides the receiver by aDecimalNumber, and returns the quotient, a newly created DecimalNumber.


byMultiplyingBy

public static next.util.DecimalNumber byMultiplyingBy(next.util.DecimalNumber aDecimalNumber)

Multiplies the receiver by aDecimalNumber, and returns the product, a newly created DecimalNumber.


byMultiplyingByPowerOf10

public static next.util.DecimalNumber byMultiplyingByPowerOf10(int power)

Multiplies the receiver by 10 raised to the power power, and returns the product, a newly created DecimalNumber.


byRaisingToPower

public static next.util.DecimalNumber byRaisingToPower(int power)

Raises the receiver to power, and returns the result, a newly created DecimalNumber.


bySubtracting

public static next.util.DecimalNumber bySubtracting(next.util.DecimalNumber aDecimalNumber)

Subtracts aDecimalNumber from the receiver, and returns the difference, a newly created DecimalNumber.


compare

public int compare(next.util.DecimalNumber aDecimalNumber)

Compares the receiver with aDecimalNumber and returns 1 if aDecimalNumber is less than the receiver, 0 if they are equal, or -1 if aDecimalNumber is greater than the receiver.


doubleValue

public double doubleValue()

Returns the receiver's value as a double, converting it as necessary.


floatValue

public float floatValue()

Returns the receiver's value as a float, converting it as necessary.


initWithMantissaAndExponent

protected void initWithMantissaAndExponent(long mantissa, int exponent)

Initializes the receiver to the number specified by the arguments. The arguments express a number in a type of scientific notation that requires the mantissa to be an integer. So, for example, if the number to be represented is 1.23, it's expressed as 123x10-2. Thus, mantissa is 123 and exponent is -2.


initWithString

protected void initWithString(java.lang.String aString)

Returns a DecimalNumber equivalent to aString. Besides digits, aString can include an initial "+" or "-," a single "E" or "e", to indicate the exponent of a number in scientific notation, and a single decimal separator to divide the fractional from the integral part of the number. Whether the decimal separator is a period (as in the United States) or a comma (as in France) depends on the default locale.


intValue

public int intValue()

Returns the receiver's value as an integer, converting it as necessary.


isNaN

public boolean isNaN()

Returns true if the receiver has the value NaN (not a number), false otherwise.


longValue

public long longValue()

Returns the receiver's value as a long integer, converting it as necessary.


newWithOperation

protected static next.util.DecimalNumber newWithOperation(int operation, next.util.DecimalNumber aDecimalNumber)

Returns a newly-created DecimalNumber that is computed from the reciever and aDecimalNumber. The operator used in the computation depends on operation; the following are valid values for operation:

1
The result is obtained by adding aDecimalNumber to the receiver.
2
The result is obtained by subtracting aDecimalNumber from the receiver.
3
The result is obtained by multiplying the receiver by aDecimalNumber.
4
The result is obtained by dividing the receiver by aDecimalNumber.
5
The result is obtained by converting aDecimalNumber to an unsigned integer, and then raising the receiver to that power.
6
The result is obtained by converting aDecimalNumber to a short, and then raising the receiver to the resulting power of 10.


valueOf

public static next.util.DecimalNumber valueOf(java.lang.String aString)

Creates and returns a DecimalNumber equivalent to aString. Besides digits, aString can include an initial "+" or "-," a single "E" or "e", to indicate the exponent of a number in scientific notation, and a single decimal separator to divide the fractional from the integral part of the number. Whether the decimal separator is a period (as in the United States) or a comma (as in France) depends on the default locale.