Skip to content

Instantly share code, notes, and snippets.

@greghelton
Last active April 27, 2026 05:58
Show Gist options
  • Select an option

  • Save greghelton/fa40efdfdeb8e024e8bb11de7b9c8748 to your computer and use it in GitHub Desktop.

Select an option

Save greghelton/fa40efdfdeb8e024e8bb11de7b9c8748 to your computer and use it in GitHub Desktop.
IBM's Decimal Arithmetic Library for Java

The IBM Decimal Arithmetic Library for Java enables Java applications to duplicate the results of COBOL's arithmetic with extreme precision.

Location of the blog post announcing the 2.0 version. https://community.ibm.com/community/user/blogs/gregory-cernera/2026/04/07/ibm-decimal-arithmetic-library-for-java-v20-releas
The post is also the location of the original code.
Note: The published code didn't compile so I researched the issues and made changes. The code I post here did give me a clean compile however, running this code at home, I get a runtime error since I don't have the IBM Dataaccess product on my laptop.

This is a tiny project that I ran from the terminal shell. I used vim to edit the files.
I used Maven to download the jars because the only known source was the Maven repo.
I had to use javap (the java profiler) to find the static INSTANCE variable in the DAAFactory class which was a change I found necessary to make. javap also showed me the correct paths for the classes. The other necessary change was to have main throw Exception because the FormatterException used in the code on the announcement post doesn't exist in the jar I downloaded from the Maven repo.

These are the commands used in this project.
mvn dependency:copy-dependencies -DoutputDirectory=./lib
export IBMJAR=.:./lib/decimal-arithmetic-2.0.0.jar:./lib/ibmjzos-2.4.11.3.jar
javap -cp lib/decimal-arithmetic-2.0.0.jar com.ibm.arithmetic.decimal.daa.DAAFactory
javac -cp .:$IBMJAR TestInterestExample.java
mvn clean install
java -cp .:$IBMJAR TestInterestExample

<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-app</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>com.ibm.jzos</groupId>
<artifactId>decimal-arithmetic</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.ibm.jzos</groupId>
<artifactId>ibmjzos</artifactId>
<version>2.4.11.3</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>local-repo</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>
</project>
import com.ibm.arithmetic.decimal.DecimalPrecision;
import com.ibm.arithmetic.decimal.daa.DAAVariable;
import com.ibm.arithmetic.decimal.daa.DAAPrecision;
import com.ibm.arithmetic.decimal.daa.DAAFactory;
import com.ibm.arithmetic.decimal.daa.DAADecimal;
import com.ibm.arithmetic.decimal.edit.Formatter;
public class TestInterestExample {
private static final DAAFactory df = DAAFactory.INSTANCE;
public static void main (String [] args) throws Exception {
DAAPrecision prec17s2 = new DAAPrecision(17, 2, true) ;
DAAPrecision prec8s6 = new DAAPrecision(8, 6, true) ;
DAAVariable b = df.createDecimalVariable(prec17s2, df.createDecimal(963807195502L,2));
DAADecimal c = df.createDecimal(180945931154L, 2) ;
DAADecimal p = df.createDecimal(81090, 6);
DAADecimal n = df.createDecimal(30);
// COMPUTE MN = (1 + P) ** N
DAAVariable mn = df.createDecimalVariable(prec8s6,p.plus(1).toThePowerOf(n)) ;
// COMPUTE B = (B + C) * MN + C * ( (MN - 1) / P - 1) .
b.set(b.plus(c).times(mn).plus(c.times(mn.minus(1).dividedBy(p).minus(1) ) ) ) ;
System.out.println(b.format(Formatter.fromString("$*(14) 9.99") ));
System.out.println(b.format(Formatter.fromString ("$$$, $$$, $$$, $$$, $$9.99") ));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment