使用Powershell更改区域设置

问题描述 投票:4回答:1

我试图谷歌这个但没有成功。是否可以将十进制分隔符更改为“。”和Powershell中的“千人”分隔符?

编辑:更准确地说,是否可以更改系统设置。我会在控制面板/区域设置中手动执行...

先感谢您!

powershell regional-settings
1个回答
7
投票

如果要在系统级别进行更改:

Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sDecimal -Value "."
Set-ItemProperty -Path "HKCU:\Control Panel\International" -Name sThousand -Value ","

如果要在线程级别进行更改:

$culture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")
$culture.NumberFormat.NumberDecimalSeparator = "."
$culture.NumberFormat.NumberGroupSeparator = ","
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture

然后你可以得到预期的输出:

[double]$x = 12345.67890
"{0:N2}" -f $x

这是输出:

12,345.68
© www.soinside.com 2019 - 2024. All rights reserved.