
Please check the Below sample code. Here the output is not accurate.. By the use of the BigDecimal, the below issue won't be observed. But is there any way to fix this by using NumberFormat and DecimalFormat
double localDoubleValue = 12345678987654321d; NumberFormat localNf = NumberFormat.getInstance();
System.out.println("Format using NumberFormat : "+localNf.format(localDoubleValue));
if (localNf instanceof DecimalFormat) { DecimalFormat localDf = (DecimalFormat) localNf; System.out.println("Format using DecimalFormat : "+localDf.format(localDoubleValue)); }
Output :
Format using NumberFormat : 12,345,678,987,654,320
Format using DecimalFormat : 12,345,678,987,654,320
Any suggesions are appreciated....
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.