Convert IBM packed decimal / zoned decimal in java
Post Date: 2017-09-12
There is a Java library called IBM Toolbox for Java or JTOpen, a open source version can convert to/from IBM decimal format of packed decimal and zoned decimal in Java.
To use it, include jt400.jar in your class path and below is an example for coverting packed decimal.
/**
* Java BigDecimal to Packed Decimal
*/
//15 means total number of digits, 5 means number of decimal places
AS400PackedDecimal packedDecimal = new AS400PackedDecimal(15, 5);
BigDecimal javaBigDecimal = new BigDecimal("1000.12345");
byte[] convertedBytesArray = packedDecimal.toBytes(javaBigDecimal);
/**
* Packed Decimal to Java Big Decimal
*/
BigDecimal convertedBigDecimal = (BigDecimal)packedDecimal.toObject(convertedBytesArray);
References: