Scrip to change $culture.NumberFormat.NumberGroupSeparator

Johana Romero Melo 1 Reputation point
2021-06-09T05:38:40.543+00:00

Hi all,

I got some apps that work with dot format and others with comma format. To avoid going to control panel i created the following scrip that changes the format of NumberGroupSeparator and NumberDecimalSeparato. Yhe scrip used to work but I do not know what happens.

Swaps the number format from 1,000.23 to 1.000,23 or vice-versa

$culture = Get-Culture
if ($culture.NumberFormat.NumberDecimalSeparator -eq ',') {
$culture.NumberFormat.NumberDecimalSeparator = '.'
$culture.NumberFormat.NumberGroupSeparator = ','
} else {
$culture.NumberFormat.NumberDecimalSeparator = ','
$culture.NumberFormat.NumberGroupSeparator = '.'
}
Set-Culture $culture

Now, the script work when swamping from comma to dot but not vice verse.

Does someone know what is the issue?

Regards,
Johana

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2021-06-09T06:54:56.103+00:00

    Hi,

    I tested the script and it worked as expected. Did you run Get-Culture again to update $culture after Set-Culture?

    103714-image.png

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Johana Romero Melo 1 Reputation point
    2021-06-09T22:48:51.99+00:00

    Hi IanXue-MSFT,

    Thank you for your replay.
    Yes, when I check the NumberFormat properties it seems like it has changed. But When I go to excel, it is still using dot as NumberDecimalSeparator
    103998-screenshot-2021-06-10-084708.png

    103974-image.png

    If I change the decimal symbol from the control panel to comma manually, and the run the script it does change it to dot.
    But from dot to comma it does not work.

    0 comments No comments

  3. Anonymous
    2021-06-10T03:49:50.23+00:00

    Hi,

    You may try the workaround of modifying the registry values. It works on my machine after restarting Excel.

    $path = 'HKCU:\Control Panel\International'  
    Set-ItemProperty -Path $path -Name 'sDecimal' -Value '.'  
    Set-ItemProperty -Path $path -Name 'sThound' -Value ','  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  4. Johana Romero Melo 1 Reputation point
    2021-06-15T22:40:00.813+00:00

    Hi anXue-MSFT,

    My only worry is that the script is used by everyone at the office. I would prefer not to play around with the regedit.

    Thank you for your idea. I will certainly try it.

    Johana

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.