abranhe / bigdecimal

✖︎ Arithmetic operations in BigDecimal made easier

Home Page:https://git.io/bigdecimal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool









✖︎ Arithmetic operations in BigDecimal made easier

See Big Decimal wiki

Why?

  • No big deal working with BigDecimal operations
  • Clean and focused
  • Actively maintained

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/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"/>

Using on your project

import com.abranhe.bigdecimal.Operations;

Usage

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
}

API

Addition

Add two BigDecimal numbers

public static BigDecimal add(BigDecimal x, BigDecimal y);

Parameters:

  • x - Big decimal number
  • y - Big decimal number

Returns:

Addition of x plus y

Subtraction

Add two BigDecimal numbers

public static BigDecimal subtract(BigDecimal x, BigDecimal y);

Parameters:

  • x - Big decimal number
  • y - Big decimal number

Returns:

Subtraction of x minus y

Multiplication

Multiplication between two BigDecimal numbers

public static BigDecimal multiply(BigDecimal x, BigDecimal y);

Parameters:

  • x - Big decimal number
  • y - Big decimal number

Returns:

Multiplication of x times y

Division

Division between two BigDecimal numbers

public static BigDecimal divide(BigDecimal x, BigDecimal y, int scale, RoundingMode roundingMode);

Parameters:

  • x - Big decimal number
  • y - Big decimal number
  • scale - Scale of the BigDecimal quotient to be returned
  • roundingMode - Rounding mode to apply

Returns:

Division of x by y

Default Division

Division between two BigDecimal numbers

public static BigDecimal divide(BigDecimal x, BigDecimal y);

Parameters:

  • x - Big decimal number
  • y - Big decimal number

Default

  • scale - 5
  • roundingMode - CEILING

Returns:

Division of x by y

Team

Carlos Abraham Logo
Carlos Abraham

License

MIT License © Carlos Abraham

About

✖︎ Arithmetic operations in BigDecimal made easier

https://git.io/bigdecimal

License:MIT License


Languages

Language:Java 100.0%