What I might want is a technique to change a twofold over to a string that gathers utilizing the half-together strategy - for example on the off chance that the decimal to be adjusted is 5, it generally gathers together to the following number. This is the standard technique for adjusting the vast majority expect as a rule.
I additionally might want just huge digits to be shown - for example, there ought not to be any following zeroes.
I know one strategy for doing this is to utilize the
String. format
technique:
String.format("%.5g%n", 0.912385);
returns:
0.91239
which is great, however, it always displays numbers with 5 decimal places even if they are not significant:
String.format("%.5g%n", 0.912300);
returns:
0.91230
Another method is to use the
DecimalFormatter:
DecimalFormat df = new DecimalFormat("#.#####");
df.format(0.912385);
returns:
0.91238
However, as you can see this uses half-even rounding. That is it will round down if the previous digit is even. What I'd like is this:
*0.912385 -> 0.91239
0.912300 -> 0.9123
What is the best way to achieve this in Java?