You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using ToString() on e.g, a double value will use current culture to format the value.
The resulting string value is not likely to be parseable at receiving end if current locale uses different decimal separator than standard English dot '.'
To Reproduce
// Set current locale in OS settings - e.g., da-DK
var request = new RestRequest(...)
.AddParameter("DoubleValue", 1.234);
Expected behavior
String value for parameter should be formatted with invariant culture format if possible.
Expected string value "1.234"
Actual string value: "1,234"
Suggestion:
For instance for IFormattable values, use the IFormattable.ToString(string?, IFormatProvider?) overload
Suggested implementation:
Change value.ToString() to value.ToStringInvariant()
which could be implemented as:
static string? ToStringInvariant<T>(this T value) => value switch
{
null => null,
IFormattable f => f.ToString(null, CultureInfo.InvariantCulture),
_ => value.ToString(),
};
Desktop (please complete the following information):
OS: Windows 11
.NET version 8
Version 112.1
The text was updated successfully, but these errors were encountered:
Describe the bug
Using
ToString()
on e.g, adouble
value will use current culture to format the value.The resulting string value is not likely to be parseable at receiving end if current locale uses different decimal separator than standard English dot '.'
To Reproduce
Expected behavior
String value for parameter should be formatted with invariant culture format if possible.
Expected string value
"1.234"
Actual string value:
"1,234"
Suggestion:
For instance for
IFormattable
values, use theIFormattable.ToString(string?, IFormatProvider?)
overloadSuggested implementation:
Change
value.ToString()
tovalue.ToStringInvariant()
which could be implemented as:
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: