com.informix.jdbc

## Class IfxDecimal

- java.lang.Object
- - com.informix.jdbc.IfxObject
  - - com.informix.jdbc.IfxDecimal

    public class IfxDecimal
    extends IfxObject

### Field Summary

Fields
`static short` `BYTEMASK`
`static short` `BYTEMASK7`
`static short` `BYTESHIFT`
`static short` `BYTESIGNED`
`protected byte[]` `dec_dgts` Array of base 100 digits (2 per byte)
`protected short` `dec_exp` Exponent in base 100
`protected short` `dec_ndgts` Base 100 digits
`protected short` `dec_pos` Sign.
`static short` `DECPOSNEGATIVE` indicates NEGATIVE decimal number
`static short` `DECPOSNULL` indicates NULL decimal number
`static short` `DECPOSPOSITIVE` indicates POSITIVE decimal number
`static int` `DECSIZE` number of bytes allocated for IFX DECIMAL
`static java.lang.String` `digChar`

### Fields inherited from class com.informix.jdbc.IfxObject

`conn, extendedID, extendedName, extendedOwner, ifxType, isNull, jdbcType, sourceType, trace, typeMap, used_in_update`

### Constructor Summary

Constructors
Constructor and Description
`IfxDecimal()` Null Decimal constructor
`IfxDecimal(java.math.BigDecimal n)` Constructs an IfxDecimal given a java.math.BigDecimal
`IfxDecimal(byte[] b)` Constructs an IfxDecimal given an Informix internal decimal byte array.

### Method Summary

Methods
`protected void` `computeEncodedLength()` Compute the precision and scale of the value
`protected static int` `decLength(int length)` Return the storage/network size of this decimal bases on the encoded length.
`boolean` `equals(java.lang.Object other)` Find out whether two objects are equal.
`protected int` `extractExponent(java.lang.String num, int start)` Given number string checks if it contains an exponent checking from start char.
`void` `fromBoolean(boolean val)` Converted to the BigDecimal value.
`void` `fromBoolean(java.lang.Boolean val)` Convert a Boolean to a BigDecimal value.
`void` `fromBoolean(java.lang.Boolean val, int scale)`
`void` `fromByte(byte val)` Converted to the BigDecimal value.
`void` `fromByte(java.lang.Byte val)` Converted from a Byte to a BigDecimal value.
`void` `fromByte(java.lang.Byte val, int scale)`
`void` `fromDecimal(java.math.BigDecimal val)` Converted to the BigDecimal value.
`void` `fromDecimal(java.math.BigDecimal val, int scale)`
`void` `fromDecimal(java.math.BigDecimal val, int scale, short encodedLength)`
`void` `fromDouble(double val)` Converted to the BigDecimal value.
`void` `fromDouble(java.lang.Double val)` Convert a Double to a BigDecimal value.
`void` `fromDouble(java.lang.Double val, int scale)`
`void` `fromFloat(float val)` Converted to the BigDecimal value.
`void` `fromFloat(java.lang.Float val)` Convert a Float to a BigDecimal value.
`void` `fromFloat(java.lang.Float val, int scale)`
`void` `fromIfx(byte[] b, int offset, int length, short prec)` Convert BigDecimal value from the given Informix network format
`void` `fromIfx(byte[] b, short prec)` Convert BigDecimal value from the given Informix network format
`void` `fromInt(int val)` Converted to the BigDecimal value.
`void` `fromInt(java.lang.Integer val)` Convert a Integer to a BigDecimal value.
`void` `fromInt(java.lang.Integer val, int scale)`
`void` `fromLong(long val)` Converted to the BigDecimal value.
`void` `fromLong(java.lang.Long val)` Convert from a Long to a BigDecimal value.
`void` `fromLong(java.lang.Long val, int scale)`
`void` `fromShort(short val)` Converted to the BigDecimal value.
`void` `fromShort(java.lang.Short val)` Convert from a Short to the BigDecimal value.
`void` `fromShort(java.lang.Short val, int scale)`
`void` `fromString(java.lang.String str)` Convert from String value.
`void` `fromString(java.lang.String str, int scale)`
`short` `getEncodedLength()` Get the encoded length with precision
`protected static java.lang.String` `getIfxTypeName(int length)` Given the length of a decimal, return the full decimal type.
`int` `getScale()`
`protected static int` `precDec(int length)` Return the decimal precision of a decimal type (digits to right).
`protected static int` `precTot(int length)` Return the total precision of a decimal type.
`void` `setEncodedLength(int encodedLength)` Set the encoded length with precision
`boolean` `toBoolean()` Return the Boolean value of the object.
`byte` `toByte()` Return the byte value of the object.
`java.math.BigDecimal` `toDecimal()` Return the BigDecimal value of the object.
`double` `toDouble()` Return the double value of the object.
`float` `toFloat()` Return the float value of the object.
`byte[]` `toIfx()` Convert BigDecimal value into Informix network format
`byte[]` `toIfxTuple()` Convert BigDecimal value into Informix tuple format
`int` `toInt()` Return the integer value of the object.
`long` `toLong()` Return the long value of the object.
`java.lang.Object` `toObject()` Return IfxDecimal cast as Object.
`short` `toShort()` Return the short value of the object.
`java.lang.String` `toString()` Convert value to a string.

### Methods inherited from class com.informix.jdbc.IfxObject

`clear, clearWarning, fromAsciiStream, fromAsciiStream, fromBinaryStream, fromBinaryStream, fromBlob, fromBytes, fromCharacterStream, fromCharacterStream, fromClob, fromDate, fromIfx, fromIfx, fromIfx, fromIfx, fromInputStream, fromInputStream, fromIntervalDF, fromIntervalYM, fromObject, fromObject, fromObject, fromString, fromTime, fromTimestamp, get_used_in_update, getWarning, isNull, nullify, set_used_in_update, setConnection, setExtendedTypeName, setIfxType, setTypeMap, toAsciiStream, toBinaryStream, toBlob, toBytes, toCharacterStream, toClob, toDate, toIfxBSONObject, toInputStream, toInterval, toIntervalDF, toIntervalYM, toObject, toTime, toTimestamp, toUnloadString, unnullify`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### dec_exp

    protected short dec_exp

Exponent in base 100

#### dec_pos

    protected short dec_pos

Sign. 1 (pos), 0 (neg) -1 (null)

#### dec_ndgts

    protected short dec_ndgts

Base 100 digits

#### dec_dgts

    protected byte[] dec_dgts

Array of base 100 digits (2 per byte)

#### digChar

    public static final java.lang.String digChar

See Also:
  Constant Field Values

#### DECSIZE

    public static final int DECSIZE

number of bytes allocated for IFX DECIMAL

See Also:
  Constant Field Values

#### DECPOSNULL

    public static final short DECPOSNULL

indicates NULL decimal number

See Also:
  Constant Field Values

#### DECPOSPOSITIVE

    public static final short DECPOSPOSITIVE

indicates POSITIVE decimal number

See Also:
  Constant Field Values

#### DECPOSNEGATIVE

    public static final short DECPOSNEGATIVE

indicates NEGATIVE decimal number

See Also:
  Constant Field Values

#### BYTESHIFT

    public static final short BYTESHIFT

See Also:
  Constant Field Values

#### BYTEMASK

    public static final short BYTEMASK

See Also:
  Constant Field Values

#### BYTESIGNED

    public static final short BYTESIGNED

See Also:
  Constant Field Values

#### BYTEMASK7

    public static final short BYTEMASK7

See Also:
  Constant Field Values

### Constructor Detail

#### IfxDecimal

    public IfxDecimal()
               throws java.sql.SQLException

Null Decimal constructor

Throws:
  `java.sql.SQLException`

#### IfxDecimal

    public IfxDecimal(java.math.BigDecimal n)
               throws java.sql.SQLException

Constructs an IfxDecimal given a java.math.BigDecimal

Parameters:
  `n` - BigDecimal from which equivalent Decimal is created
Throws:
  `java.sql.SQLException`

#### IfxDecimal

    public IfxDecimal(byte[] b)
               throws java.sql.SQLException

Constructs an IfxDecimal given an Informix internal decimal byte array.

Parameters:
  `b` - byte from Informix internal decimal data
Throws:
  `java.sql.SQLException`

### Method Detail

#### toIfx

    public byte[] toIfx()

Convert BigDecimal value into Informix network format

Overrides:
  `toIfx` in class `IfxObject`
Returns:
  a byte array representation of this data type in Informix network format

#### toIfxTuple

    public byte[] toIfxTuple()

Convert BigDecimal value into Informix tuple format

Overrides:
  `toIfxTuple` in class `IfxObject`
Returns:
  a byte array representation of this data type in Informix tuple format

#### fromIfx

    public void fromIfx(byte[] b,
               short prec)

Convert BigDecimal value from the given Informix network format

Overrides:
  `fromIfx` in class `IfxObject`
Parameters:
  `prec` - Informix internal representation for precision
  `b` - byte from Informix internal decimal data

#### fromIfx

    public void fromIfx(byte[] b,
               int offset,
               int length,
               short prec)

Convert BigDecimal value from the given Informix network format

Overrides:
  `fromIfx` in class `IfxObject`
Parameters:
  `prec` - Informix internal representation for precision
  `offset` - into byte array
  `length` - data length
  `b` - byte from Informix internal decimal data

#### toObject

    public java.lang.Object toObject()
                              throws java.sql.SQLException

Return IfxDecimal cast as Object.

Overrides:
  `toObject` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### toByte

    public byte toByte()
                throws java.sql.SQLException

Return the byte value of the object.

Overrides:
  `toByte` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromByte

    public void fromByte(java.lang.Byte val)
                  throws java.sql.SQLException

Converted from a Byte to a BigDecimal value.

Overrides:
  `fromByte` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromByte

    public void fromByte(java.lang.Byte val,
                int scale)
                  throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromByte

    public void fromByte(byte val)
                  throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromByte` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toShort

    public short toShort()
                  throws java.sql.SQLException

Return the short value of the object.

Overrides:
  `toShort` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromShort

    public void fromShort(java.lang.Short val)
                   throws java.sql.SQLException

Convert from a Short to the BigDecimal value.

Overrides:
  `fromShort` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromShort

    public void fromShort(java.lang.Short val,
                 int scale)
                   throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromShort

    public void fromShort(short val)
                   throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromShort` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toInt

    public int toInt()
              throws java.sql.SQLException

Return the integer value of the object.

Overrides:
  `toInt` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromInt

    public void fromInt(java.lang.Integer val)
                 throws java.sql.SQLException

Convert a Integer to a BigDecimal value.

Overrides:
  `fromInt` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromInt

    public void fromInt(java.lang.Integer val,
               int scale)
                 throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromInt

    public void fromInt(int val)
                 throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromInt` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toLong

    public long toLong()
                throws java.sql.SQLException

Return the long value of the object.

Overrides:
  `toLong` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromLong

    public void fromLong(java.lang.Long val)
                  throws java.sql.SQLException

Convert from a Long to a BigDecimal value.

Overrides:
  `fromLong` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromLong

    public void fromLong(java.lang.Long val,
                int scale)
                  throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromLong

    public void fromLong(long val)
                  throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromLong` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toFloat

    public float toFloat()
                  throws java.sql.SQLException

Return the float value of the object.

Overrides:
  `toFloat` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromFloat

    public void fromFloat(java.lang.Float val)
                   throws java.sql.SQLException

Convert a Float to a BigDecimal value.

Overrides:
  `fromFloat` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromFloat

    public void fromFloat(java.lang.Float val,
                 int scale)
                   throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromFloat

    public void fromFloat(float val)
                   throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromFloat` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toDouble

    public double toDouble()
                    throws java.sql.SQLException

Return the double value of the object.

Overrides:
  `toDouble` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromDouble

    public void fromDouble(java.lang.Double val)
                    throws java.sql.SQLException

Convert a Double to a BigDecimal value.

Overrides:
  `fromDouble` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromDouble

    public void fromDouble(java.lang.Double val,
                  int scale)
                    throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromDouble

    public void fromDouble(double val)
                    throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromDouble` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toDecimal

    public java.math.BigDecimal toDecimal()
                                   throws java.sql.SQLException

Return the BigDecimal value of the object.

Overrides:
  `toDecimal` in class `IfxObject`
Returns:
  the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromDecimal

    public void fromDecimal(java.math.BigDecimal val)
                     throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromDecimal` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromDecimal

    public void fromDecimal(java.math.BigDecimal val,
                   int scale)
                     throws java.sql.SQLException

Overrides:
  `fromDecimal` in class `IfxObject`
Throws:
  `java.sql.SQLException`

#### fromDecimal

    public void fromDecimal(java.math.BigDecimal val,
                   int scale,
                   short encodedLength)
                     throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### toBoolean

    public boolean toBoolean()
                      throws java.sql.SQLException

Return the Boolean value of the object.

Overrides:
  `toBoolean` in class `IfxObject`
Returns:
  the boolean value If the BigDecimal is 0 , then return false Otherwise, return true.
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromBoolean

    public void fromBoolean(java.lang.Boolean val)
                     throws java.sql.SQLException

Convert a Boolean to a BigDecimal value.

Overrides:
  `fromBoolean` in class `IfxObject`
Parameters:
  `val` - the value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromBoolean

    public void fromBoolean(java.lang.Boolean val,
                   int scale)
                     throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### fromBoolean

    public void fromBoolean(boolean val)
                     throws java.sql.SQLException

Converted to the BigDecimal value.

Overrides:
  `fromBoolean` in class `IfxObject`
Parameters:
  `val` - the value if val is false, then set the BigDecimal to 0 otherwise, set it to 1
Throws:
  `java.sql.SQLException` - if the conversion failed

#### toString

    public java.lang.String toString()

Convert value to a string.

Overrides:
  `toString` in class `IfxObject`
Returns:
  a string value representation of the BigDecimal, or null on error

#### fromString

    public void fromString(java.lang.String str)
                    throws java.sql.SQLException

Convert from String value.

Overrides:
  `fromString` in class `IfxObject`
Parameters:
  `str` - the String value
Throws:
  `java.sql.SQLException` - if the conversion failed

#### fromString

    public void fromString(java.lang.String str,
                  int scale)
                    throws java.sql.SQLException

Throws:
  `java.sql.SQLException`

#### equals

    public boolean equals(java.lang.Object other)

Find out whether two objects are equal.

Overrides:
  `equals` in class `IfxObject`
Parameters:
  `other` - the other object to compare with
Returns:
  true if the objects are equal

#### getScale

    public int getScale()

#### getEncodedLength

    public short getEncodedLength()

Get the encoded length with precision

Overrides:
  `getEncodedLength` in class `IfxObject`
Returns:
  the encoded length with precision of the object

#### setEncodedLength

    public void setEncodedLength(int encodedLength)

Set the encoded length with precision

#### computeEncodedLength

    protected void computeEncodedLength()

Compute the precision and scale of the value

#### extractExponent

    protected int extractExponent(java.lang.String num,
                      int start)

Given number string checks if it contains an exponent checking from start char. Exponent if given must be of the form: e+-nnn. Returns a number equal to the exponent Returns 0 if no exponent found.

Parameters:
  `num` - number as a string which may have an exponent
  `start` - position where to start looking in string

#### precTot

    protected static int precTot(int length)

Return the total precision of a decimal type. This information is encoded in the length. See /vobs/tristarm/incl/decimal.h: PRECTOT macro decimal(16,2) <-- '16'

Parameters:
  `length` - - the length of the decimal type.
Returns:
  the total precision.

#### precDec

    protected static int precDec(int length)

Return the decimal precision of a decimal type (digits to right). This information is encoded in the length. See /vobs/tristarm/incl/decimal.h: PRECDEC decimal(16,2) <-- '2'

Parameters:
  `length` - - the length of the decimal type.
Returns:
  the decimal precision.

#### decLength

    protected static int decLength(int length)

Return the storage/network size of this decimal bases on the encoded length. See /vobs/tristarm/incl/decimal.h: DECLENGTH

Parameters:
  `length` - - the length of the decimal type.
Returns:
  the decimal precision.

#### getIfxTypeName

    protected static java.lang.String getIfxTypeName(int length)

Given the length of a decimal, return the full decimal type. Call precTot() and precDec() to calculate the 'x' and 'y' of 'decimal(x,y)'. Returns the string 'decimal(x, y)'

Parameters:
  `length` - - the length of the decimal type.
Returns:
  the decimal : e.g. 'decimal(16, 2)'