package test;import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.Random;public class Testday1 {
public static void main(String[] ages) throws Exception{
text_1();
// System.out.println(uu);
} private static void text_1() {
// TODO Auto-generated method stub
BigDecimal b = new BigDecimal(0.12345678910111213141516);
System.out.println(b);
double d = 0.12345678910111213141516;
System.out.println(d);
}为什么这段代码执行的结果会是这样的:一直搞不清楚BigDecimal类有什么用。
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.Random;public class Testday1 {
public static void main(String[] ages) throws Exception{
text_1();
// System.out.println(uu);
} private static void text_1() {
// TODO Auto-generated method stub
BigDecimal b = new BigDecimal(0.12345678910111213141516);
System.out.println(b);
double d = 0.12345678910111213141516;
System.out.println(d);
}为什么这段代码执行的结果会是这样的:一直搞不清楚BigDecimal类有什么用。
http://jeelee.iteye.com/blog/652003
其他类型都有界限值,运算一复杂,数字越大,精确度越低,你可以试试。很多简单的运算它也不精确的
BigDecimal好像在128以下会使用int型,它可以自动转换自身类型