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 220 views
220 views asked Jul 24, 2022 by avibootz
1 answer 219 views
219 views asked Nov 2, 2016 by avibootz
2 answers 255 views
1 answer 216 views
1 answer 204 views
1 answer 174 views
174 views asked Jun 3, 2024 by avibootz
1 answer 235 views
...