2

I have run into weird situation with string representation of double.PositiveInfinity and NegativeInfinity in Windows Server 2016. Our tester found that my program (written in C# .NET v.4) generated a symbol '∞' instead of "Infinity" that it was supposed to do in the culture "en-US". That prevented a further processing of the data. The Region and Language settings in Control Panel show the only configured culture: English (United States). I quickly made a little app that checked and dumped the culture information to text file and handed the app to the tester to run on the machine. This is what I got from him:

2018-04-23 15:14:25 Current culture:
Symbol = 'en-US'; Native Name = 'English (United States)'; English Name = 'English (United States)';
Positive Infinity string: ∞;
Negative Infinity string: -∞;
NaN string: NaN

On any other computer (Windows 7, Windows Server 2012) I get:

Current culture:
Symbol = 'en-US'; Native Name = 'English (United States)'; English Name = 'English (United States)';
Positive Infinity string: Infinity;
Negative Infinity string: -Infinity;
NaN string: NaN

Does anybody know if there is place in Windows settings that overrides culture's default representation of the Infinity? Or is it Windows 2016 hiccup?

  • 3
    Hint: try invariant culture. If you cannot try invariant culture this belongs in server fault. – Joshua Apr 24 '18 at 00:28
  • _string representation_ Please explain this. ToString()? FormattedValue? You can e.g. convert a DGV.Cell.Value back with the Convert.ToDouble function though not by casting to double. – TaW Apr 24 '18 at 07:14
  • To @TaW: A) Why did you ask? Both _myVar.ToString()_ and _string.Format("...{0}...", myVar, ...)_ will produce the same result (either "Infinity" or "∞"); B) I don't need an advice how to solve the issue programmatically (the program is released already). I am looking for a way to force Windows 2016 (or .NET) to use a proper (for "en-US" ) string representation of positive/negative infinity value. – Arkady Yampolsky Apr 24 '18 at 17:06
  • Yes, this depends on the Windows version (even if the machine with the older Windows has been upgraded to the newest version of the .NET Framework, that will not help). From PowerShell, you can check quickly with `[cultureinfo]::GetCultureInfo("en-US").NumberFormat.PositiveInfinitySymbol`. There appears to be no way you can change that setting in Windows itself. In .NET, of course `var tmp = (CultureInfo)(CultureInfo.CurrentCulture.Clone()); tmp.NumberFormat.PositiveInfinitySymbol = "Infinity"; CultureInfo.CurrentCulture = CultureInfo.ReadOnly(tmp);` will help (for one current thread only). – Jeppe Stig Nielsen Jul 12 '18 at 13:40
  • (continued) Use `CultureInfo.DefaultThreadCurrentCulture = ...;` to have it changed for future threads (as well as old threads that did never change their cultures), although that works only for the current AppDomain. – Jeppe Stig Nielsen Jul 12 '18 at 13:41

0 Answers0