indriya
indriya copied to clipboard
NumberDelimiterQuantityFormat ignores NumberFormat's maximum fraction digits
Code:
final QuantityFormat format = new NumberDelimiterQuantityFormat.Builder()
.setNumberFormat(new DecimalFormat("#.000"))
.setUnitFormat(SimpleUnitFormat.getInstance())
.build();
final Quantity<Length> quantity = Quantities.get(1.23456, METRES);
System.out.println(format.format(quantity));
Expected output: 1.235 m
Actual output: 1.23456 m
Elaboration:
Since I am able to set a custom NumberFormat
, I expect the NumberDelimiterQuantityFormat
to use the NumberFormat
unaltered.
Instead, NumberDelimiterQuantityFormat
internally always sets the NumberFormat
's maximum fraction digits so that all digits are displayed.
Thanks for pointing that out including a runnable snippet. We'll try to replicate and find the cause.
@andi-huber Any thoughts about the precision influencing the NumberFormat
?
I'm also hitting this issue (with a slightly different way to build the NumberFormat
), and got pointed here after asking a StackOverflow question.
Is there a workaround that doesn't involve copy'n'paste of this code from Indriya?