Formatting Currencies

by Nov 14, 2011

Formatting numbers as currencies is straight-forward – as long as it is your own currency format:

'{0:C}' -f 12.22

If you want to output currencies in other cultures, you still can do it. Let's assume you created a currency converter and wanted to output the result in the Japanese currency format, then here is how:

$culture = New-Object System.Globalization.CultureInfo('ja-JP')
(12.22).ToString('c', $culture)

And how do you find the culture name "ja-JP" for Japan or any other nation? Have a look:

function Get-CultureInfo($keyword = '*') {
  [System.Globalization.CultureInfo]::GetCultures('AllCultures') | 
  Where-Object { $_.DisplayName -like "*$keyword*" }
}

Simply use this function "Get-CultureInfo" to find culture names:

PS> Get-CultureInfo France

LCID             Name             DisplayName
----             ----             -----------
1036             fr-FR            French (France)
1156             gsw-FR           Alsatian (France)
1155             co-FR            Corsican (France)
1154             oc-FR            Occitan (France)
1150             br-FR            Breton (France)

Twitter This Tip!
ReTweet this Tip!