How to use BigDecimal class in Java

2 Answers

0 votes
import java.math.BigDecimal;

public class MyClass {
    public static void main(String args[]) {
        BigDecimal a = new BigDecimal(99822838328382343.0);
        BigDecimal b = new BigDecimal(5.0);
        BigDecimal result = a.multiply(b); 
        
        System.out.println(result);
    }
}


/*

run:

499114191641911680

*/

 



answered Jul 25, 2019 by avibootz
0 votes
import java.math.BigDecimal;

public class MyClass {
    public static void main(String args[]) {
        BigDecimal a = new BigDecimal(3.0);
        BigDecimal b = new BigDecimal(5.5);
        BigDecimal result = a.divide(b, 10, BigDecimal.ROUND_UP);
        
        System.out.println(result);
    }
}


/*

run:

0.5454545455

*/

 



answered Jul 25, 2019 by avibootz

Related questions

1 answer 133 views
133 views asked Jul 24, 2022 by avibootz
1 answer 147 views
147 views asked Nov 2, 2016 by avibootz
2 answers 125 views
1 answer 130 views
1 answer 117 views
1 answer 97 views
97 views asked Jun 3, 2024 by avibootz
1 answer 130 views
...