This project is read-only.
1
Vote

ConvertToLongString not working properly for some negative double values

description

Hi,

I've noticed that the ConvertToLongString function does not work properly for some values. An example is:
-0.000007629394531
This gets incorrectly converted to:
00000-7629394531
The problem appears to be that the minus sign needs to be removed and then added back at the end as is done in the code that was originally used for the implementation:
http://stackoverflow.com/questions/1546113/double-to-string-conversion-without-scientific-notation
To fix this I added, after "if (!raw.Contains("E")) return raw;":
        bool negativeNumber = false;
        if (raw[0] == '-')
        {
            raw = raw.Remove(0, 1);
            negativeNumber = true;
        }
And changed the last part to:
        if (exponentValue > 0)
        {
            result = newNumber + new string('0', Math.Abs(exponentValue - decimalParts[1].Length));
        }
        else // Negative exponent
        {
            result = ("0" + separator + new string('0', Math.Abs(exponentValue + decimalParts[0].Length)) + newNumber).TrimEnd('0');
        }

        if (negativeNumber)
            result = "-" + result;         
        return result;
Assuming that this is correct, please can you integrate this back into the code base for the next version?

Regards
Simon

comments