Description
Describe the bug
There are corner cases of decimal
values that are not converted to a valid VR=DS value, causing fo-dicom to throw a validation exception.
To Reproduce
The code
var dataset = new DicomDataset();
dataset.Add(DicomTag.TableTopLateralPosition, -12345678901234.1m);
causes this exception to be thrown:
FellowOakDicom.DicomValidationException : Content "-1.2345678901E+13" does not validate VR DS: value exceeds maximum length of 16 characters
at FellowOakDicom.DicomValidation.ValidateDS(String content)
The example is of course completely bonkers in practice and I have no use case for when this would actually happen, but the fact that there exists valid decimal
values that can not be converted to a valid DS attribute is at least slightly worrying.
Expected behavior
For a decimal
to always be converted to a valid Decimal String. In this case, e.g., "-1.23456789E+13"
One solution could for example be to change the line
valueString = value.ToString("G11", CultureInfo.InvariantCulture);
in DicomDecimalString.ToDecimalString
to
valueString = value.ToString("G10", CultureInfo.InvariantCulture);
Environment
Fellow Oak DICOM version: 5.0.2.4
OS: Windows 10 x64
Platform: .NET Framework 4.8