How to convert double to BigDecimal in Java

1 Answer

0 votes
import java.math.BigDecimal;

public class MyClass {
    public static void main(String args[]) {
        double d = 12345.123;
         
        BigDecimal num = new BigDecimal(Double.toString(d));
         
        System.out.println(num);
    }
}




/*
run:

12345.123

*/

 



answered Jan 24, 2016 by avibootz
edited Nov 25, 2023 by avibootz

Related questions

2 answers 120 views
1 answer 124 views
1 answer 122 views
1 answer 110 views
1 answer 92 views
92 views asked Jun 3, 2024 by avibootz
...