-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Note: This isn't likely to arise often in practice, but is an inconsistency that should be addressed.
In most contexts, notably in string interpolation, PowerShell uses the invariant rather than the current culture for converting numbers to strings, for consistency across cultures; e.g., "$(1.2)"
yields '1.2'
in any culture, i.e. .
is always used as the decimal mark.
By contrast, when hash tables are converted to [pscustomobject]
s, which necessitates converting non-string keys to strings, keys that are either of type [double]
or [decimal]
are unexpectedly stringified based on the current culture.
Steps to reproduce
try {
$org = [cultureinfo]::CurrentCulture
[cultureinfo]::CurrentCulture = 'fr-FR' # e.g.; use a culture that uses "," as the decimal mark
([pscustomobject] @{ 1.2 = 'hi' }).'1.2' | Should -Be 'hi'
} finally {
[cultureinfo]::CurrentCulture = $org
}
Expected behavior
The test should succeed, because [double]
1.2
should always stringify to '1.2'
.
Actual behavior
The test fails, because with culture fr-FR
(French) in effect, where ,
is the decimal mark, 1.2
stringified to '1,2'
.
Expected 'hi', but got $null.
Environment data
PowerShell Core 7.2.0-preview.1