private const int SinglePrecision = 9;
private const int DoublePrecision = 17;
+ // SinglePrecisionCustomFormat and DoublePrecisionCustomFormat are used to ensure that
+ // custom format strings return the same string as in previous releases when the format
+ // would return x digits or less (where x is the value of the corresponding constant).
+ // In order to support more digits, we would need to update ParseFormatSpecifier to pre-parse
+ // the format and determine exactly how many digits are being requested and whether they
+ // represent "significant digits" or "digits after the decimal point".
+ private const int SinglePrecisionCustomFormat = 6;
+ private const int DoublePrecisionCustomFormat = 15;
+
private const int DefaultPrecisionExponentialFormat = 6;
private const int ScaleNAN = unchecked((int)0x80000000);
char fmt = ParseFormatSpecifier(format, out int precision);
byte* pDigits = stackalloc byte[DoubleNumberBufferLength];
+ if (fmt == '\0')
+ {
+ // For back-compat we currently specially treat the precision for custom
+ // format specifiers. The constant has more details as to why.
+ precision = DoublePrecisionCustomFormat;
+ }
+
NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, DoubleNumberBufferLength);
number.IsNegative = double.IsNegative(value);
}
else
{
+ Debug.Assert(precision == DoublePrecisionCustomFormat);
NumberToStringFormat(ref sb, ref number, format, info);
}
return null;
char fmt = ParseFormatSpecifier(format, out int precision);
byte* pDigits = stackalloc byte[SingleNumberBufferLength];
+ if (fmt == '\0')
+ {
+ // For back-compat we currently specially treat the precision for custom
+ // format specifiers. The constant has more details as to why.
+ precision = SinglePrecisionCustomFormat;
+ }
+
NumberBuffer number = new NumberBuffer(NumberBufferKind.FloatingPoint, pDigits, SingleNumberBufferLength);
number.IsNegative = float.IsNegative(value);
}
else
{
+ Debug.Assert(precision == SinglePrecisionCustomFormat);
NumberToStringFormat(ref sb, ref number, format, info);
}
return null;