indriya icon indicating copy to clipboard operation
indriya copied to clipboard

NumberDelimiterQuantityFormat ignores NumberFormat's maximum fraction digits

Open max-maag opened this issue 2 years ago • 2 comments

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.

max-maag avatar Aug 02 '21 10:08 max-maag

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?

keilw avatar Aug 02 '21 11:08 keilw

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?

bradh avatar Feb 20 '22 05:02 bradh