import java.math.BigDecimal;
import java.math.MathContext;
public class TestD {
public static void main(String args[]){
double d1 = 100.01234567890123456789012345678901234567890123456789;
double d2 = 2.0;
double d3 = 1.0;
double d4 = 3.0;
System.out.println(d1/d2);
System.out.println(d3/d4);
BigDecimal bd1 = new BigDecimal(100.01234567890123456789012345678901234567890123456789);
BigDecimal bd2 = new BigDecimal(2.0);
BigDecimal bd3 = new BigDecimal(1.0);
BigDecimal bd4 = new BigDecimal(3.0);
System.out.println(bd1.divide(bd2));
System.out.println(bd3.divide(bd4,MathContext.DECIMAL128));
}
}
double pi = Math.PI; // prints 3.141592653589793
But, we all know pi is a Non-terminating decimal.
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
basic hardware to learn oop advanced design patterns | 3 | 88 | |
groupSumClump challenge | 9 | 98 | |
Which is the latest version of Apache Tomcatl | 3 | 50 | |
use lov values | 2 | 24 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
21 Experts available now in Live!