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.
Title | # Comments | Views | Activity |
---|---|---|---|
wordappend challenge | 8 | 85 | |
Math question | 3 | 58 | |
Permutation and Combination | 9 | 48 | |
Error with Java/Cache JDBC Classpath | 2 | 20 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
20 Experts available now in Live!