Skip to content
Abraham Hernandez edited this page Jul 26, 2018 · 3 revisions

BigDecimal

✖︎ Arithmetic operation in BigDecimal made easier.

Table of Contents

Dependency Information

Download the latest version JAR to include it in your project

Maven

<dependency>
        <groupId>com.abranhe.bigdecimal</groupId>
        <artifactId>bigdecimal</artifactId>
        <version>1.0.1</version>
</dependency>

Gradle

compile 'com.abranhe:bigdecimal:1.0.1'

Grails

compile 'com.abranhe:bigdecimal:1.0.1'

Grape

@Grapes(
    @Grab(group='com.abranhe', module='bigdecimal', version='1.0.1')
)

Ivy

<dependency org="com.abranhe" name="bigdecimal" rev="1.0.1"/>

Importing Lib

import com.abranhe.bigdecimal.Operations;

Examples

Example 1

import com.abranhe.bigdecimal.Operations;
import java.math.BigDecimal;

public static void main(String[] args){

        BigDecimal x = new BigDecimal("124567890.0987654321");
        BigDecimal y = new BigDecimal("987654321.123456789");

        System.out.println(Operations.add(x, y));
        //=> 1112222211.2222222211
}

Example 2

import java.math.BigDecimal;

public static void main(String[] args){

        BigDecimal x = new BigDecimal("124567890.0987654321");
        BigDecimal y = new BigDecimal("987654321.123456789");

        Operations o = new Operations();
        System.out.println(com.abranhe.bigdecimal.Operations.divide(x, y));
        //=> 0.12613
}

Example 3

import com.abranhe.bigdecimal.Operations.divide;
import java.math.RoundingMode;
import java.math.BigDecimal;

public static void main(String[] args){

        BigDecimal x = new BigDecimal("124567890.0987654321");
        BigDecimal y = new BigDecimal("987654321.123456789");

        System.out.println(divide(x, y, 9, RoundingMode.FLOOR));
        //=> 0.126124988
}