DICOM: fix width of values with DS VR
Fixes #4376.
With this change, bfconvert -noflat -compression JPEG CMU-1.ndpi CMU-1.dcm or similar and then dcdump CMU-1_0_0.dcm should show:
...
> (0x0028,0x0030) DS Pixel Spacing VR=<DS> VL=<0x0022> <0.00045641259698\0.00045506257110 >
...
In addition to the issue noted in #4376, this checks other values of type DS to make sure the width is correct. I don't necessarily like the current implementation of formatFixedWidth, so definitely open to better ideas for how to turn a double into a string of no more than n characters total. DecimalFormat and String.format(...) can easily give a string with at least n characters, or with a fixed precision, but I couldn't find a good concise way to guarantee no more than n characters.
For Pixel Spacing, the fixed width is set to 15 so that even if the padding space were included, the value will still have no more than 16 characters.
... > (0x0028,0x0030) DS Pixel Spacing VR=<DS> VL=<0x0022> <0.00045641259698\0.00045506257110 > ...
Why not use scientific notation?
Here's somewhat related issue, just for the reference - we went quite a bit back and forth on how to ensure best use of the limited character length: https://github.com/QIICR/dcmqi/issues/414 (that code is C++).
... I couldn't find a good concise way to guarantee no more than n characters.
You may want to look at my Java code, which handles a bunch of fringe conditions to try to maximize the preserved precision, in this method https://www.dclunie.com/pixelmed/software/javadoc/com/pixelmed/utils/FloatFormatter.html#toStringOfFixedMaximumLength-double-int-boolean-java.util.Locale-
The class source is attached for your convenience:
Here's that function in a GitHub repo where I synchronize @dclunie pixelmed, for convenience:
https://github.com/fedorov/pixelmed/blob/f9b7844749f15fd8d6523d119f4c3792738c40a3/com/pixelmed/utils/FloatFormatter.java#L105-L227