While selenium testing a .net core application on my local machine, I noticed that my percent strings (.ToString("p2")) were showing no space between the number and the %, different from our testing server's page. After some research, it seems the Culture info has been changed somehow on my Windows 10 box. Does anyone know how to reset it back to the defaults? Or change the settings?
get-culture
LCID Name DisplayName
---- ---- -----------
1033 en-US English (United States)
(get-culture).NumberFormat
CurrencyDecimalDigits : 2
CurrencyDecimalSeparator : .
IsReadOnly : True
CurrencyGroupSizes : {3}
NumberGroupSizes : {3}
PercentGroupSizes : {3}
CurrencyGroupSeparator : ,
CurrencySymbol : $
NaNSymbol : NaN
CurrencyNegativePattern : 0
NumberNegativePattern : 1
PercentPositivePattern : 1
PercentNegativePattern : 1
NegativeInfinitySymbol : -∞
NegativeSign : -
NumberDecimalDigits : 2
NumberDecimalSeparator : .
NumberGroupSeparator : ,
CurrencyPositivePattern : 0
PositiveInfinitySymbol : ∞
PositiveSign : +
PercentDecimalDigits : 2
PercentDecimalSeparator : .
PercentGroupSeparator : ,
PercentSymbol : %
PerMilleSymbol : ‰
NativeDigits : {0, 1, 2, 3…}
DigitSubstitution : None
PercentPositivePattern & PercentNegativePattern are set to 1 instead of 0. Also, IsReadOnly seems to be true when other boxes show false.
Checked my region info. Everything looks correct.
Indeed, the formatting of percentages in the
en-USculture has changed in a recent version of Windows 10:[1]Windows 7:
Windows 10, version 1903:
To get the old behavior back for the current thread only (not globally, and not persistently), you can do the following:
Thereafter,
(1).Tostring('p2')again yields100 %.Note: In Windows PowerShell / .NET Framework, you can also modify the properties of
[cultureinfo]::CurrentCulturedirectly (no cloning required). While that simplifies the solution, note that it is no longer supported in PowerShell Core / .NET Core, where the predefined cultures are read-only.Taking a step back:
As Eric MSFT notes:
For stability of formats across times and cultures you should use the the invariant culture,
InvariantCulture(emphasis added):[1] Sean1215 (the OP) reports that the change must have occurred sometime after OS build 14393 and before 16299. Due to different group-policy-based Windows update schedules across teams in his organization, his machine happened to use a more recent build than that of colleagues'.