Format of BigDecimal number

前端 未结 4 1973
太阳男子
太阳男子 2020-12-19 20:08
BigDecimal val = BigDecimal.valueOf(0.20);
System.out.println(a);

I want to store in val a value 0.20 and not 0.2. What I

4条回答
  •  情话喂你
    2020-12-19 20:52

    EDIT: this answer is wrong as pointed out in the comments :| thx Andreas_D

    The problem is that there is no mathematical difference between 0.2 and 0.20 so your only chance is to display a certain number of digits after the decimal point. Once you store 0.2 or 0.20 in a BigDecimal they are indistinguishable from each other

提交回复
热议问题