com.ibm.as400.access
Class AS400DecFloat

java.lang.Object
  extended by com.ibm.as400.access.AS400DecFloat
All Implemented Interfaces:
AS400DataType, Serializable, Cloneable

public class AS400DecFloat
extends Object
implements AS400DataType

The AS400DecFloat class provides a converter between a BigDecimal object and a DecimalFloat type.

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
 
Fields inherited from interface com.ibm.as400.access.AS400DataType
TYPE_ARRAY, TYPE_BIN2, TYPE_BIN4, TYPE_BIN8, TYPE_BYTE_ARRAY, TYPE_DECFLOAT, TYPE_FLOAT4, TYPE_FLOAT8, TYPE_PACKED, TYPE_STRUCTURE, TYPE_TEXT, TYPE_UBIN2, TYPE_UBIN4, TYPE_ZONED
 
Constructor Summary
Constructor and Description
AS400DecFloat(int numDigits)
          Constructs an AS400DecFloat object.
 
Method Summary
Modifier and Type Method and Description
 Object clone()
          Creates a new AS400DecFloat object that is identical to the current instance.
 int getByteLength()
          Returns the byte length of the data type.
 Object getDefaultValue()
          Returns a Java object representing the default value of the data type.
 int getInstanceType()
          Returns instance type
 Class getJavaType()
          Returns the Java class that corresponds with this data type.
 int getNumberOfDigits()
          Returns the total number of digits in the decfloat number.
static BigDecimal roundByMode(BigDecimal bd, int precision, String roundingMode)
          Rounds the precision of a BigDecimal by removing least significant digits from the right side of the precision.
 byte[] toBytes(double doubleValue)
          Converts the specified Java object to server format.
 int toBytes(double doubleValue, byte[] as400Value)
          Converts the specified Java object into server format in the specified byte array.
 int toBytes(double doubleValue, byte[] as400Value, int offset)
          Converts the specified Java object into server format in the specified byte array.
 byte[] toBytes(Object javaValue)
          Converts the specified Java object to server format.
 int toBytes(Object javaValue, byte[] as400Value)
          Converts the specified Java object into server format in the specified byte array.
 int toBytes(Object javaValue, byte[] as400Value, int offset)
          Converts the specified Java object into server format in the specified byte array.
 double toDouble(byte[] as400Value)
          Converts the specified server data type to a Java double value.
 double toDouble(byte[] as400Value, int offset)
          Converts the specified server data type to a Java double value.
 Object toObject(byte[] as400Value)
          Converts the specified server data type to a Java object.
 Object toObject(byte[] as400Value, int offset)
          Converts the specified server data type to a Java object (BigDecimal).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AS400DecFloat

public AS400DecFloat(int numDigits)
Constructs an AS400DecFloat object.

Parameters:
numDigits - The number of digits (16 or 34).
Method Detail

clone

public Object clone()
Creates a new AS400DecFloat object that is identical to the current instance.

Specified by:
clone in interface AS400DataType
Overrides:
clone in class Object
Returns:
The new object.

getByteLength

public int getByteLength()
Returns the byte length of the data type.

Specified by:
getByteLength in interface AS400DataType
Returns:
The number of bytes in the server representation of the data type.

getDefaultValue

public Object getDefaultValue()
Returns a Java object representing the default value of the data type.

Specified by:
getDefaultValue in interface AS400DataType
Returns:
The BigDecimal object with a value of zero.

getInstanceType

public int getInstanceType()
Returns instance type

Specified by:
getInstanceType in interface AS400DataType
Returns:
AS400DataType.TYPE_DECFLOAT.

getJavaType

public Class getJavaType()
Returns the Java class that corresponds with this data type.

Specified by:
getJavaType in interface AS400DataType
Returns:
BigDecimal.class.

getNumberOfDigits

public int getNumberOfDigits()
Returns the total number of digits in the decfloat number.

Returns:
The number of digits.

toBytes

public byte[] toBytes(Object javaValue)
Converts the specified Java object to server format.

Specified by:
toBytes in interface AS400DataType
Parameters:
javaValue - The object corresponding to the data type. It must be an instance of BigDecimal and the BigDecimal must have a less than or equal to number of digits.
Returns:
The server representation of the data type.

toBytes

public int toBytes(Object javaValue,
                   byte[] as400Value)
Converts the specified Java object into server format in the specified byte array.

Specified by:
toBytes in interface AS400DataType
Parameters:
javaValue - The object corresponding to the data type. It must be an instance of BigDecimal and the BigDecimal must have a less than or equal to number of digits.
as400Value - The array to receive the data type in server format. There must be enough space to hold the server value.
Returns:
The number of bytes in the server representation of the data type.

toBytes

public int toBytes(Object javaValue,
                   byte[] as400Value,
                   int offset)
Converts the specified Java object into server format in the specified byte array.

Specified by:
toBytes in interface AS400DataType
Parameters:
javaValue - An object corresponding to the data type. It must be an instance of BigDecimal or String (if value is "NaN", "Infinity", or "-Infinity").
as400Value - The array to receive the data type in server format. There must be enough space to hold the server value.
offset - The offset into the byte array for the start of the server value. It must be greater than or equal to zero.
Returns:
The number of bytes in the server representation of the data type.

toBytes

public byte[] toBytes(double doubleValue)
Converts the specified Java object to server format.

Parameters:
doubleValue - The value to be converted to server format. If the decimal part of this value needs to be truncated, it will be rounded based on decfloat rounding mode property.
Returns:
The server representation of the data type.

toBytes

public int toBytes(double doubleValue,
                   byte[] as400Value)
Converts the specified Java object into server format in the specified byte array.

Parameters:
doubleValue - The value to be converted to server format. If the decimal part of this value needs to be truncated, it will be rounded based on decfloat rounding mode property.
as400Value - The array to receive the data type in server format. There must be enough space to hold the server value.
Returns:
The number of bytes in the server representation of the data type.

toBytes

public int toBytes(double doubleValue,
                   byte[] as400Value,
                   int offset)
Converts the specified Java object into server format in the specified byte array.

Parameters:
doubleValue - The value to be converted to server format. If the decimal part of this value needs to be truncated, it will be rounded based on decfloat rounding mode property.
as400Value - The array to receive the data type in server format. There must be enough space to hold the server value.
offset - The offset into the byte array for the start of the server value. It must be greater than or equal to zero.
Returns:
The number of bytes in the server representation of the data type.

toDouble

public double toDouble(byte[] as400Value)
Converts the specified server data type to a Java double value.

Parameters:
as400Value - The array containing the data type in server format. The entire data type must be represented.
Returns:
The Java double value corresponding to the data type.

toDouble

public double toDouble(byte[] as400Value,
                       int offset)
Converts the specified server data type to a Java double value.

Parameters:
as400Value - The array containing the data type in server format. The entire data type must be represented.
offset - The offset into the byte array for the start of the server value. It must be greater than or equal to zero.
Returns:
The Java double value corresponding to the data type.

toObject

public Object toObject(byte[] as400Value)
Converts the specified server data type to a Java object.

Specified by:
toObject in interface AS400DataType
Parameters:
as400Value - The array containing the data type in server format. The entire data type must be represented.
Returns:
The BigDecimal object corresponding to the data type.

toObject

public Object toObject(byte[] as400Value,
                       int offset)
Converts the specified server data type to a Java object (BigDecimal).

Specified by:
toObject in interface AS400DataType
Parameters:
as400Value - The array containing the data type in server format. The entire data type must be represented and the data type must have valid packed decimal format.
offset - The offset into the byte array for the start of the server value. It must be greater than or equal to zero.
Returns:
The BigDecimal object corresponding to the data type.

roundByMode

public static BigDecimal roundByMode(BigDecimal bd,
                                     int precision,
                                     String roundingMode)
Rounds the precision of a BigDecimal by removing least significant digits from the right side of the precision. (least significant digits could be left or right of implicit decimal point)

Parameters:
bd - BigDecimal to truncate.
precision - to truncate bd to. (16 or 34)
roundingMode - to use when truncating