✖︎ Arithmetic operations in BigDecimal made easier
See Big Decimal wiki
- No big deal working with BigDecimal operations
- Clean and focused
- Actively maintained
Download the latest version JAR to include it in your project
<dependency>
<groupId>com.abranhe.bigdecimal</groupId>
<artifactId>bigdecimal</artifactId>
<version>1.0.1</version>
</dependency>
compile 'com.abranhe:bigdecimal:1.0.1'
@Grapes(
@Grab(group='com.abranhe', module='bigdecimal', version='1.0.1')
)
<dependency org="com.abranhe" name="bigdecimal" rev="1.0.1"/>
import com.abranhe.bigdecimal.Operations;
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
}
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
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 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 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
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
Carlos Abraham |
MIT License © Carlos Abraham