Recently new job and got a question regarding an error in the software from a customer. The error is “Conversion from string ‘0.5’ to type ‘double’ is not valid.”
I believe I have found the offending line. Because the customer is in France and has his computers settings all in french (numbering system, language,…) that the “0.5” can’t be casted to french number version of “0,5” The French system has no decimals anywhere in their numbers. So, if string.format sees “0.5” it won’t know what to do, because there is no ‘.’ character to be casted to double in french culture settings. Am I right here?
context.Append(String.Format("{0} {1} exceeds fine {2} limit of {3:N0}", _
context.OccupancyState, context.Size, _
Reg.Alert.ToLower, context.Limit))
Where context.Size holds the “0.5” string.
Does format.string take into account the culture settings, or am I missing something here?
EDIT:
Just tried it on french windows VM, and (unfortunately) it was able to parse it as “0,5” successfully…So maybe that isn’t the problem?
You need to convert the string to a double first, otherwise
String.Formatwill just concat the string without any formatting.Now
string.Formatwill useSystem.Globalization.CultureInfo.CurrentCulturewhen it formats the double to a string again.