BigDecimal val = BigDecimal.valueOf(0.20);
System.out.println(a);
I want to keep the value in val 0.20, not 0.2. What can I do?
I do not think that I can use NumberFormatin this case, when I use NumberFormat, I should know what the length of my decimal number is! I can have 0.20 or 0.5000, I do not know the exact length of the decimal number, so I can not use:
DecimalFormat df = new DecimalFormat("#0.00");
or
DecimalFormat df = new DecimalFormat("#0.00000");
Perhaps I have only 2 numbers after the point or 5 numbers or more, and this program does not work:
BigDecimal a = BigDecimal.valueOf(0.20);
System.out.println(a);
NumberFormat nf1 = NumberFormat.getInstance();
System.out.println(nf1.format(0.5000));
Mehdi source
share