文章优先发布在个人博客,后续更新可能忘记同步到CSDN。
个人博客本篇文章位置: https://www.xdx97.com/article?bamId=664138763500257280
1、尽可能的使用BigDecimal去代替,double。虽然BigDecimal操作起来麻烦一些,但是在展示的时候,和在精度方便确实有优势。
2、通过实验,我得出当数据大于1000W的时候,double就会使用科学计数法展示,下面给出两个办法来解决这个问题。
public static void main(String[] args) {
double j = 10000000.1;
System.out.println(j);
// 方法一
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);
System.out.println(nf.format(j));
//方法二
System.out.println(new BigDecimal(j + "").toString());
}