5

I have tried to google this out but with no success. Is it possible to change the Decimal Separator to "." and Thousands Separator to "," in Powershell?

EDIT: To be more precise, is it possible to change the system setting. As I would do manually in Control panel / regional settings...

Thank you in advance!

Mario
  • 377
  • 5
  • 18

1 Answers1

13

If you want to change at system level:

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

If you want to change at thread level:

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

Then you can get the expected output:

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

Here is the output:

12,345.68
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • 1
    @Mario Thanks for the correction. In such cases when you find an important typo or an obvious mistake in an answer, feel free to edit the answer. – Reza Aghaei Dec 20 '17 at 01:28
  • 1
    Just for future reference, Reza's answer totally worked but instead of 'sGrouping' in second example, 'sThousand' should be used – Mario Dec 19 '17 at 19:27