I am trying to convert a double value to Packed decimal COBOL format PIC S9(5)V9(4) COMP-3/Packed decimal COBOL format PIC S9(3)V9(4) COMP-3 format in JAVA, see below example :

Double Value : 00000.6775 Converted to Packed Decimal : ^@^FS,^@

Is this conversation possible in java?

1

There are 1 answers

0
Bruce Martin On

Similar questions have been answered multiple times already on Stack overflow

For s9(5)V9(4) comp-3, 123.45 is represented in byte format as

00 12 34 50 0c

The C is the sign

Yes this is possible, the JRecord package will do it (may truncate extra digits though).

The approach is

  • to Convert double to a unsigned and unscaled long / BigInteger i.e 123.45 --> 1234500 (for s9(5)v9(4))
  • Convert the long to packed decimal

At this point there are several approaches