Oracle Fusion Middleware
Oracle WebLogic Server API Reference
11g Release 1 (10.3.4)

Part Number E13941-04

weblogic.wtc.jatmi
Class Decimal

java.lang.Object
  extended by java.lang.Number
      extended by weblogic.wtc.jatmi.Decimal
All Implemented Interfaces:
Serializable, Comparable

public class Decimal
extends Number
implements Comparable

This class provides a Java implementation of the Tuxedo packed decimal type. Packed decimals appear only in Tuxedo View buffers. The class methods provide convenience routines to create packed decimals from Strings and numbers and to convert a packed decimal object to a String or number. A Decimal encodes a number as an array of bytes in base-100 and a signed exponent (-64 to +63). The byte array is of fixed size with the implied decimal point to the left of the first byte. The exponent represents powers of 100. A special exponent value DECPOSNULL indicates a Decimal with null (undefined) value.

See Also:
Serialized Form

Field Summary
static int DECPOSNULL
          Exponent value indicating a null Decimal, i.e., a Decimal with undefined value.
static int DECSIZE
          Size of the array of bytes representing the digits of the Decimal.
 
Constructor Summary
Decimal()
          Constructs a newly allocated Decimal object with null value.
Decimal(byte bval)
          Constructs a newly allocated Decimal object from a byte value.
Decimal(double value)
          Constructs a newly allocated Decimal object from a double value.
Decimal(float value)
          Constructs a newly allocated Decimal object from a float value.
Decimal(int ival)
          Constructs a newly allocated Decimal object from an int value.
Decimal(int sign, int exponent, int numDigits, byte[] digits)
          Constructs a newly allocated Decimal object using the values specified by its parameters.
Decimal(long lval)
          Constructs a newly allocated Decimal object from a long value.
Decimal(short sval)
          Constructs a newly allocated Decimal object from a short value.
Decimal(String str)
          Constructs a newly allocated Decimal object from a String value.
 
Method Summary
 BigDecimal bigDecimalValue()
          Converts the Decimal to a BigDecimal value.
 byte byteValue()
          Converts the Decimal to a byte value.
 int compareTo(Decimal other)
          Compares two Decimal objects numerically.
 int compareTo(Object other)
          Compares this Decimal object to another object.
 byte[] digits()
          Returns the actual decimal digits.
 double doubleValue()
          Converts the Decimal to a double value.
 boolean equals(Object obj)
          Compares this object to another object.
 int exponent()
          Returns the exponent of the Decimal value.
 float floatValue()
          Converts the Decimal to a float value.
 int intValue()
          Converts the Decimal to an int value.
 long longValue()
          Converts the Decimal to a long value.
 Decimal negate()
          Creates a newly allocated Decimal whose value is (-this).
 int numDigits()
          Returns the number of significant digits in the Decimal value.
 short shortValue()
          Converts the Decimal to a short value.
 int sign()
          Returns the sign of the Decimal value.
 String toString()
          Converts the Decimal to a String.
static String toString(Decimal dec)
          Converts the input Decimal to a String.
static Decimal valueOf(String s)
          Constructs a newly allocated Decimal object from a String value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DECSIZE

public static final int DECSIZE
Size of the array of bytes representing the digits of the Decimal.

See Also:
Constant Field Values

DECPOSNULL

public static final int DECPOSNULL
Exponent value indicating a null Decimal, i.e., a Decimal with undefined value. Null Decimals cannot be compared numerically with other Decimals.

See Also:
Constant Field Values
Constructor Detail

Decimal

public Decimal()
Constructs a newly allocated Decimal object with null value. The sign of the object is set to DECPOSNULL.

See Also:
Decimal.DECPOSNULL

Decimal

public Decimal(int sign,
               int exponent,
               int numDigits,
               byte[] digits)
Constructs a newly allocated Decimal object using the values specified by its parameters.

Parameters:
sign - the sign to set; 1 indicates a positive value, 0 a negative value and DECPOSNULL a null value.
exponent - the exponent to set. It must be between -64 and +63.
numDigits - the number of significant digits in the digits array. This value must be less than or equal to DECSIZE.
digits - an array of bytes representing the actual digits of the decimal value. The bytes must be base-100 digits (0-99). Only the first numDigits bytes are used.
Throws:
NumberFormatException - if any of the input parameters do not obey the described constraints
See Also:
Decimal.DECPOSNULL, Decimal.DECSIZE

Decimal

public Decimal(double value)
        throws NumberFormatException
Constructs a newly allocated Decimal object from a double value.

Parameters:
value - the double value to convert.
Throws:
NumberFormatException - if the value would overflow or underflow when converted to Decimal or if the value represents a NaN or infinity.

Decimal

public Decimal(float value)
        throws NumberFormatException
Constructs a newly allocated Decimal object from a float value.

Parameters:
value - the float value to convert.
Throws:
NumberFormatException - if the value represents a NaN or infinity.

Decimal

public Decimal(String str)
        throws NumberFormatException
Constructs a newly allocated Decimal object from a String value. The String is converted to a Decimal value as if by the valueOf method.

Parameters:
str - the String value to convert.
Throws:
NumberFormatException - if the value is in the wrong format or would overflow or underflow when converted to Decimal.
See Also:
Decimal.valueOf(String)

Decimal

public Decimal(long lval)
Constructs a newly allocated Decimal object from a long value.

Parameters:
lval - the long value to convert. If lval represents the smallest long value (Long.MIN_VALUE), a Decimal with null value is created.

Decimal

public Decimal(int ival)
Constructs a newly allocated Decimal object from an int value.

Parameters:
ival - the int value to convert. If ival represents the smallest int value (Integer.MIN_VALUE), a Decimal with null value is created.

Decimal

public Decimal(short sval)
Constructs a newly allocated Decimal object from a short value.

Parameters:
sval - the short value to convert. If sval represents the smallest short value (Short.MIN_VALUE), a Decimal with null value is created.

Decimal

public Decimal(byte bval)
Constructs a newly allocated Decimal object from a byte value.

Parameters:
bval - the byte value to convert. If bval represents the smallest byte value (Byte.MIN_VALUE), a Decimal with null value is created.
Method Detail

exponent

public int exponent()
Returns the exponent of the Decimal value. The exponent represents powers of 100.

Returns:
the exponent, from -64 to +63.

sign

public int sign()
Returns the sign of the Decimal value.

Returns:
The sign of the value; 1 indicates a positive value, 0 a negative value and DECPOSNULL a null value.
See Also:
Decimal.DECPOSNULL

numDigits

public int numDigits()
Returns the number of significant digits in the Decimal value.

Returns:
the number of significant digits in the Decimal value.

digits

public byte[] digits()
Returns the actual decimal digits. Each digit is in base-100.

Returns:
an array of bytes representing the actual decimal digits. The decimal point is to the left of the first digit.

negate

public Decimal negate()
Creates a newly allocated Decimal whose value is (-this).

Returns:
a Decimal whose value is (-this). If the original Decimal has a null value, that is, its sign is DECPOSNULL, a new null Decimal is returned.
See Also:
Decimal.DECPOSNULL

bigDecimalValue

public BigDecimal bigDecimalValue()
Converts the Decimal to a BigDecimal value.

Returns:
the BigDecimal value representing the Decimal. If the Decimal has a null value, a new BigDecimal(Double.MIN_VALUE) is returned.

doubleValue

public double doubleValue()
Converts the Decimal to a double value.

Specified by:
doubleValue in class Number
Returns:
the double value representing the Decimal. If the Decimal has a null value, Double.MIN_VALUE is returned.

floatValue

public float floatValue()
                 throws NumberFormatException
Converts the Decimal to a float value.

Specified by:
floatValue in class Number
Returns:
the float value representing the Decimal. If the Decimal has a null value, Float.MIN_VALUE is returned.
Throws:
NumberFormatException - if the Decimal value would cause overflow when converted to a float.

longValue

public long longValue()
               throws NumberFormatException
Converts the Decimal to a long value.

Specified by:
longValue in class Number
Returns:
the long value representing the Decimal. If the Decimal has a null value, Long.MIN_VALUE is returned.
Throws:
NumberFormatException - if the Decimal value cannot be represented as a long.

intValue

public int intValue()
             throws NumberFormatException
Converts the Decimal to an int value.

Specified by:
intValue in class Number
Returns:
the int value representing the Decimal. If the Decimal has a null value, Integer.MIN_VALUE is returned.
Throws:
NumberFormatException - if the Decimal value cannot be represented as an int.

shortValue

public short shortValue()
                 throws NumberFormatException
Converts the Decimal to a short value.

Overrides:
shortValue in class Number
Returns:
the short value representing the Decimal. If the Decimal has a null value, Short.MIN_VALUE is returned.
Throws:
NumberFormatException - if the Decimal value cannot be represented as a short.

byteValue

public byte byteValue()
               throws NumberFormatException
Converts the Decimal to a byte value.

Overrides:
byteValue in class Number
Returns:
the byte value representing the Decimal. If the Decimal has a null value, Byte.MIN_VALUE is returned.
Throws:
NumberFormatException - if the Decimal value cannot be represented as a byte.

toString

public String toString()
                throws NumberFormatException
Converts the Decimal to a String. The String is in the format that the Java Double.toString method would generate for an equivalent double value.

Overrides:
toString in class Object
Returns:
the String value representing the Decimal.
Throws:
NumberFormatException - if the Decimal value cannot be represented as a double.

toString

public static String toString(Decimal dec)
                       throws NumberFormatException
Converts the input Decimal to a String. The String is in the format that the Java Double.toString method would generate for an equivalent double value.

Parameters:
dec - the Decimal object to convert.
Returns:
the String value representing the Decimal.
Throws:
NumberFormatException - if the Decimal value cannot be represented as a double.

valueOf

public static Decimal valueOf(String s)
                       throws NumberFormatException
Constructs a newly allocated Decimal object from a String value. The String is converted to a Decimal value. The String must be in the format accepted by the Java Double.parseDouble method.

Parameters:
str - the String value to convert.
Returns:
the Decimal value created
Throws:
NumberFormatException - if the value is in the wrong format or would overflow or underflow when converted to Decimal.

compareTo

public int compareTo(Object other)
              throws NumberFormatException
Compares this Decimal object to another object. If the other object is a Decimal, this function behaves like compareTo(Decimal). Otherwise, it throws a ClassCastException.

Specified by:
compareTo in interface Comparable
Parameters:
obj - the other object to compare
Returns:
the value 0 if the two objects are numerically equal; the value -1 if the current object is numerically less than the other; the value 1 if the current object is numerically greater than the other.
Throws:
ClassCastException - if obj is not a Decimal
NumberFormatException - if either of the objects has a null value, that is, if their exponent is equal to DECPOSNULL.
See Also:
Decimal.DECPOSNULL

compareTo

public int compareTo(Decimal other)
              throws NumberFormatException
Compares two Decimal objects numerically. Neither object can have a null value.

Parameters:
other - a Decimal that is compared against this object.
Returns:
the value 0 if the two objects are numerically equal; the value -1 if the current object is numerically less than other; the value 1 if the current object is numerically greater than other.
Throws:
NumberFormatException - if either of the objects has a null value, that is, if their exponent is equal to DECPOSNULL.
See Also:
Decimal.DECPOSNULL

equals

public boolean equals(Object obj)
Compares this object to another object. The result is true if the other object is non-null and represents a Decimal object with the same value as the current object. The values are equal if the objects have identical bit patterns. Note that null valued Decimals may be compared in this operation (unlike compareTo(Decimal)).

Overrides:
equals in class Object
Parameters:
obj - the other object to compare
Returns:
true if the other object is a Decimal with the same value as the current object.

Copyright 1996, 2010, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Oracle Fusion Middleware
Oracle WebLogic Server API Reference
11g Release 1 (10.3.4)

Part Number E13941-04