-
Notifications
You must be signed in to change notification settings - Fork 4
Home
Abraham Hernandez edited this page Jul 26, 2018
·
3 revisions
✖︎ Arithmetic operation in BigDecimal made easier.
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'
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
}