AS/400 Toolbox for Java \ Access classes \ Dataconversion anddescription \ Numeric

Numeric conversion

Conversion classes for numeric data simply convert numeric data from AS/400 format to Java format. Supported types are shown in the following table:

Numeric Type Description
AS400Bin2 Converts between a signed two-byte AS/400 number and a Java Short object.
AS400Bin4 Converts between a signed four-byte AS/400 number and a Java Integer object.
AS400ByteArray Converts between two byte arrays. This is useful because the converter correctly zero-fills and pads the target buffer.
AS400Float4 Converts between a signed four-byte floating point AS/400 number and a Java Float object.
AS400Float8 Converts between a signed eight-byte floating point AS/400 number and a Java Double object.
AS400PackedDecimal Converts between a packed-decimal AS/400 number and a Java BigDecimal object.
AS400UnsignedBin2 Converts between an unsigned two-byte AS/400 number and a Java Integer object.
AS400UnsignedBin4 Converts between an unsigned four-byte AS/400 number and a Java Long object.
AS400ZonedDecimal Converts between a zoned-decimal AS/400 number and a Java BigDecimal object.

The following example shows conversion from an AS/400 numeric type to a Java int:

                       // Create a buffer to hold the AS/400
                       // type. Assume the buffer is filled
                       // with numeric AS/400 data by data
                       // queues, program call, etc.
     byte[] data = new byte[100];

                       // Create a converter for this
                       // AS/400 data type.
     AS400Bin4 bin4Converter = new AS400Bin4();

                       // Convert from AS/400 type to Java
                       // object. The number starts at the
                       // beginning of the buffer.
     Integer intObject = (Integer) bin4Converter.toObject(data,0);

                       // Extract the simple Java type from
                       // the Java object.
     int i = intObject.intValue();

The following example shows conversion from a Java int to an AS/400 numeric data type:

                       // Create a Java object that contains
                       // the value to convert.
     Integer intObject = new Integer(22);

                       // Create a converter for the AS/400
                       // data type.
     AS400Bin4 bin4Converter = new AS400Bin4();

                       // Convert from Java object to
                       // AS/400 type.
     byte[] data = bin4Converter.toBytes(intObject);

                       // Find out how many bytes of the
                       // buffer were filled with the
                       // AS/400 value.
     int length = bin4Converter.getByteLength();

[ Information Center Home Page | Feedback ] [ Legal | AS/400 Glossary ]