Closed cdwork closed 6 months ago
Original post "Incorrect Double.ToString formatting up to an thrown Exceptions"
Double.ToString using formatting throws an exception. For example:
(0.1).ToString("F3"); // Work correct (0.6-0.5).ToString("F3"); // throw exception (0.099999999999999978).ToString("F3"); // throw exception
because of var result = FormatNative(value, formatCh, precision); in System.Number.Format(object value, bool isInteger, string format, NumberFormatInfo info) will return a string, firstly, that does not match the value, and secondly, with “non-text” characters.
var result = FormatNative(value, formatCh, precision);
value = 0.099999999999999978 formatCh = "F" precision = 3 result = "0.011000000000000000000000000000000000000000000000000 \b$] 0p0�a�0�aD"
different values reproduce exceptions with different specified formatting precision.
link on forum: https://forums.ghielectronics.com/t/incorrect-double-tostring-formatting-up-to-an-thrown-exceptions/24796
seem duplicate but need verify: https://github.com/ghi-electronics/TinyCLR-Libraries/issues/629
Original post "Incorrect Double.ToString formatting up to an thrown Exceptions"
Double.ToString using formatting throws an exception. For example:
because of
var result = FormatNative(value, formatCh, precision);
in System.Number.Format(object value, bool isInteger, string format, NumberFormatInfo info) will return a string, firstly, that does not match the value, and secondly, with “non-text” characters.different values reproduce exceptions with different specified formatting precision.