I've asked this question already here in the comments:
How to round a number to n decimal places in Java.
I'm trying to convert a double into a string with a fixed number of decimal places. In the question above the solution is quite simple. When using
String.format("%.4g", 0.1234712)
I get the expected result, a number rounded to 4 digits:
0.1235
But when there are zeros after the decimal dot:
String.format("%.4g", 0.000987654321)
This will return:
0,0009877
It looks like the function is ignoring the leading zeros in the digits.
I know that I could just define a new DecimalFormat but I want to understand this issue. And learn a bit about the syntax.