- <#
- .SYNOPSIS
- This script demonstrates the use of the CurrencyDecimalDigits
- .DESCRIPTION
- This script is a re-write of an MSDN sample, using PowerShell
- .NOTES
- File Name : Show-CurrencyDecimalDigits.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimaldigits%28v=vs.100%29.aspx
- .EXAMPLE
- PSH> .\Show-CurrencyDecimalDigits.ps1
- ($1,234.00)
- ($1,234.0000)
- #>
- # Get Number Format
- $nf = New-Object System.Globalization.CultureInfo "en-US", $False
- $nfi = $nf.NumberFormat
- # Display a negative value with the default number of decimal digits (2).
- [Int64] $myInt = -1234
- $myInt.ToString( "C", $nfi )
- # Displays the same value with four decimal digits.
- $nfi.CurrencyDecimalDigits = 4
- $myInt.ToString( "C", $nfi )
This blog contains PowerShell scripts, more PowerShell scripts and still more PowerShell scripts. Occasionally you may see some organisational posts.
Showing posts with label System.Globalization.CultureInfo. Show all posts
Showing posts with label System.Globalization.CultureInfo. Show all posts
Thursday, 16 May 2013
Show-CurrencyDecimalDigits.ps1
Wednesday, 17 April 2013
Show-NumberDecimalSeparator.ps1
- <#
- .SYNOPSIS
- This script demonstrates the use of the NumberDecimalSeparator
- .DESCRIPTION
- This script is a re-write of an MSDN sample, using PowerShell
- .NOTES
- File Name : Show-NumberDecimaleparatort.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/b74zyt45%28v=vs.100%29.aspx
- .EXAMPLE
- PSH> .\Show-NumberDecimalSeparator.ps1
- 123,456,789.00
- 123,456,789 00
- #>
- # Get Number Format
- $nf = New-Object System.Globalization.CultureInfo "en-US", $False
- $nfi = $nf.NumberFormat
- [Int64] $myInt = 123456789
- $myInt.ToString( "N", $nfi )
- $nfi.NumberDecimalSeparator = " "
- $myInt.ToString( "N", $nfi )
Wednesday, 13 March 2013
Show-CurrencyGroupSeparator.ps1
- <#
- .SYNOPSIS
- This script demonstrates the use of the CurrencyGroupSeparator
- .DESCRIPTION
- This script is a re-write of an MSDN sample, using PowerShell
- .NOTES
- File Name : Show-CurrencyGroupSeparator.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencygroupseparator%28v=vs.100%29.aspx
- .EXAMPLE
- PSH> .\Show-NumberGroupSizes.ps1
- $123,456,789,012,345.00
- $123 456 789 012 345.00
- #>
- # Get Number Format
- $nf = New-Object System.Globalization.CultureInfo "en-US", $False
- $nfi = $nf.NumberFormat
- # Display a value with the default separator (",").
- [Int64] $myInt = 123456789012345
- $myInt.ToString( "C", $nfi )
- # Displays the same value with a blank as the separator.
- $nfi.CurrencyGroupSeparator = " "
- $myInt.ToString( "C", $nfi )
Tuesday, 7 August 2012
Show-Formatting1.ps1
- <#
- .SYNOPSIS
- MSDN Sample Recoded in PowerShell demonstrating formatting
- .DESCRIPTION
- This sample recodes an MSDN Sample into PowerShell that
- shows some of the options of formatting using ToString() and
- various .NET formatting strings
- .NOTES
- File Name : Show-Formatting1.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/0c899ak8.aspx
- .EXAMPLE
- Psh> .\Show-Formatting1.ps1\
- 00123
- 1.20
- 01.20
- 01,20
- 0.6
- 1,234,567,890
- 1.234.567.890
- 1,234,567,890.1
- 1,234.57
- #>
- ## Start script
- [double] $value = 123;
- $value.ToString("00000")
- # Displays 00123
- $value = 1.2;
- $value.ToString("0.00", [System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 1.20
- $value.ToString("00.00",[System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 01.20
- $value.ToString("00.00",
- [System.Globalization.CultureInfo]::CreateSpecificCulture("da-DK"))
- # Displays 01,20
- $value = .56
- $value.ToString("0.0", [System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 0.6
- $value = 1234567890
- $value.ToString("0,0", [System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 1,234,567,890
- $value.ToString("0,0",
- [System.Globalization.CultureInfo]::CreateSpecificCulture("el-GR"))
- # Displays 1.234.567.890
- $value = 1234567890.123456;
- $value.ToString("0,0.0", [System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 1,234,567,890.1
- $value = 1234.567890;
- $value.ToString("0,0.00", [System.Globalization.CultureInfo]::InvariantCulture)
- # Displays 1,234.57
Sunday, 22 January 2012
New-SpanishCulture.ps1
- <#
- .SYNOPSIS
- This script creates a Spanish cultureinfo object with a traditional
- sort and another with an international sort. The script then compares them.
- .DESCRIPTION
- This script re-implements an MSDN sample.
- .NOTES
- File Name : New-SpanishCulture.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx
- .EXAMPLE
- C:\foo> .\New-SpanishCulture.ps1
- PROPERTY INTERNATIONAL TRADITIONAL
- CompareInfo CompareInfo - es-ES CompareInfo - es-ES_tradnl
- DisplayName Spanish (Spain) Spanish (Spain)
- EnglishName Spanish (Spain, International Sort) Spanish (Spain, Traditional Sort)
- IsNeutralCulture False False
- IsReadOnly False
- LCID 3082 1034
- Name es-ES es-ES
- NativeName Español (España, alfabetización internacional) Español (España, alfabetización tradicional)
- Parent es es
- TextInfo TextInfo - es-ES TextInfo - es-ES_tradnl
- ThreeLetterISOLanguageName spa spa
- ThreeLetterWindowsLanguageName ESN ESP
- TwoLetterISOLanguageName es es
- Comparing [llegar] and [lugar]
- With myCIintl.CompareInfo.Compare: -1
- With myCItrad.CompareInfo.Compare: 1
- #>
- # Create and initialize the CultureInfo which uses the international sort
- $myCIintl = New-Object System.Globalization.CultureInfo "es-ES", $false
- # Create and initialize the CultureInfo which uses the traditional sort
- $myCItrad = New-Object System.Globalization.CultureINfo 0x040A, $false
- # Display the properties of each culture.
- "{0,-31}{1,-47}{2,-25}" -f "PROPERTY", "INTERNATIONAL", "TRADITIONAL"
- "{0,-31}{1,-47}{2,-25}" -f "CompareInfo", $myCIintl.CompareInfo, $myCItrad.CompareInfo
- "{0,-31}{1,-47}{2,-25}" -f "DisplayName", $myCIintl.DisplayName, $myCItrad.DisplayName
- "{0,-31}{1,-47}{2,-25}" -f "EnglishName", $myCIintl.EnglishName, $myCItrad.EnglishName
- "{0,-31}{1,-47}{2,-25}" -f "IsNeutralCulture", $myCIintl.IsNeutralCulture, $myCItrad.IsNeutralCulture
- "{0,-31}{1,-47}{2,-25}" -f "IsReadOnly", $myCIintl.$IsReadOnly, $myCItrad.IsReadOnly
- "{0,-31}{1,-47}{2,-25}" -f "LCID", $myCIintl.LCID, $myCItrad.LCID
- "{0,-31}{1,-47}{2,-25}" -f "Name", $myCIintl.Name, $myCItrad.Name
- "{0,-31}{1,-47}{2,-25}" -f "NativeName", $myCIintl.NativeName, $myCItrad.NativeName
- "{0,-31}{1,-47}{2,-25}" -f "Parent", $myCIintl.Parent, $myCItrad.Parent
- "{0,-31}{1,-47}{2,-25}" -f "TextInfo", $myCIintl.TextInfo, $myCItrad.TextInfo
- "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterISOLanguageName", $myCIintl.ThreeLetterISOLanguageName, $myCItrad.ThreeLetterISOLanguageName
- "{0,-31}{1,-47}{2,-25}" -f "ThreeLetterWindowsLanguageName",$myCIintl.ThreeLetterWindowsLanguageName, $myCItrad.ThreeLetterWindowsLanguageName
- "{0,-31}{1,-47}{2,-25}" -f "TwoLetterISOLanguageName", $myCIintl.TwoLetterISOLanguageName, $myCItrad.TwoLetterISOLanguageName
- ""
- # Compare two strings using myCIintl
- "Comparing [llegar] and [lugar]"
- " With myCIintl.CompareInfo.Compare: {0}" -f $myCIintl.CompareInfo.Compare("llegar", "lugar")
- " With myCItrad.CompareInfo.Compare: {0}" -f $myCItrad.CompareInfo.Compare("llegar", "lugar")
Show-ChineeseParentCulture.ps1
- <#
- .SYNOPSIS
- This script displays the parent culture of each
- specific culture using the Chinese language.
- .DESCRIPTION
- This script looks at each Chineese culture and displays
- the culture name and the parent.
- .NOTES
- File Name : Show-ChineeseParentCulture.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx
- .EXAMPLE
- C:\foo> .\Show-ChineeseParentCulture.ps1
- SPECIFIC CULTURE PARENT CULTURE
- 0x0804 zh-CN Chinese (Simplified, PRC) 0x0004 zh-CHS Chinese (Simplified) Legacy
- 0x0C04 zh-HK Chinese (Traditional, Hong Kong S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) Legacy
- 0x1404 zh-MO Chinese (Traditional, Macao S.A.R.) 0x7C04 zh-CHT Chinese (Traditional) Legacy
- 0x1004 zh-SG Chinese (Simplified, Singapore) 0x0004 zh-CHS Chinese (Simplified) Legacy
- 0x0404 zh-TW Chinese (Traditional, Taiwan) 0x7C04 zh-CHT Chinese (Traditional) Legacy
- #>
- # Display a header
- "SPECIFIC CULTURE PARENT CULTURE"
- # Determine the specific cultures that use the Chinese language, and displays the parent culture
- ForEach ($ci in [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::SpecificCultures)) {
- if ($ci.TwoLetterISOLanguageName -eq "zh")
- {
- $s1 = "0x{0} {1} {2,-40}" -f $ci.LCID.ToString("X4"), $ci.Name, $ci.EnglishName
- $s2 = "0x{0} {1} {2}" -f $ci.Parent.LCID.ToString("X4"), $ci.Parent.Name, $ci.Parent.EnglishName
- "{0}{1}" -f $s1, $s2
- }
- }
Tuesday, 1 November 2011
Show-DateTimeFormatInfo.ps1
- <#
- .SYNOPSIS
- This script re-implements and MSDN sample that shows
- the different Date/Time Formatting characters and
- how they are used in formatting date/time objects.
- .DESCRIPTION
- This script Creates a date/time object, then shows formatting
- using the key Date/Time Format strings.
- .NOTES
- File Name : Show-DateTimeFormatInfo.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
- .EXAMPLE
- Left as an exercise for the reader.
- #>
- # Create and initialise a DateTimeFormatInfo associated with the en-US culture.
- $MyDTFI = (new-object System.Globalization.CultureInfo "en-US", $false ).DateTimeFormat
- # Create a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3)
- # The Gregorian calendar is the default calendar for the en-US culture
- $MyDT = new-object System.DateTime 2002, 1, 3
- # Display the format pattern associated with each format character
- "FORMAT en-US EXAMPLE"
- "CHAR VALUE OF ASSOCIATED PROPERTY, IF ANY"
- " d {0}" -f $MyDT.ToString("d", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.ShortDatePattern, "(ShortDatePattern)"
- " D {0}" -f $MyDT.ToString("D", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.LongDatePattern, "(LongDatePattern)"
- " f {0}`n" -f $MyDT.ToString("f", $MyDTFI)
- " F {0}" -f $MyDT.ToString("F", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.FullDateTimePattern, "(FullDateTimePattern)"
- " g {0}`n" -f $MyDT.ToString("g", $MyDTFI)
- " G {0}`n" -f $MyDT.ToString("G", $MyDTFI)
- " m {0}" -f $MyDT.ToString("m", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)"
- " M {0}" -f $MyDT.ToString("M", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)"
- " o {0}`n" -f $MyDT.ToString("o", $MyDTFI)
- " r {0}" -f $MyDT.ToString("r", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)"
- " R {0}" -f $MyDT.ToString("R", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)"
- " s {0}" -f $MyDT.ToString("s", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.SortableDateTimePattern, "(SortableDateTimePattern)"
- " t {0}" -f $MyDT.ToString("t", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.ShortTimePattern, "(ShortTimePattern)"
- " T {0}" -f $MyDT.ToString("T", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.LongTimePattern, "(LongTimePattern)"
- " u {0}" -f $MyDT.ToString("u", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)"
- " U {0}`n" -f $MyDT.ToString("U", $MyDTFI)
- " y {0}" -f $MyDT.ToString("y", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)"
- " Y {0}" -f $MyDT.ToString("Y", $MyDTFI)
- " {0} {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)"
Show-CurrencyDecimalSeparator.ps1
- <#
- .SYNOPSIS
- This script re-implements an MSDN script which
- shows the use of the CurrencyDecimalSeparator
- property of a numeric format info object.
- .DESCRIPTION
- This script displays a currency value using
- the default decimal separator then shows using a
- custom separator. This is repeated using a German
- culture.
- .NOTES
- File Name : Show-CurrencyDecimalSeparator.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencydecimalseparator.aspx
- .EXAMPLE
- Psh> .\Show-CurrencyDecimalSeparator.ps1
- $123,456,789.00
- $123,456,789 00
- 123.456.789,00 €
- 123.456.789 00 €
- #>
- # Get a NumberFormatInfo associated with the en-US culture
- $nfi = (new-object System.Globalization.CultureInfo "en-US", $false ).NumberFormat
- # Display a value with the default separator (".").
- $myInt = 123456789
- $myInt.ToString( "C", $nfi )
- # Display the same value with a blank as the separator.
- $nfi.CurrencyDecimalSeparator = " "
- $myInt.ToString( "C", $nfi )
- # Now get a NumberFormatInfo associated with the de-DE culture
- $nfi = (new-object System.Globalization.CultureInfo "de-DE", $false ).NumberFormat
- # Display a value with the default separator (".")
- $myInt = 123456789
- $myInt.ToString( "C", $nfi )
- # Display the same value with a blank as the separator
- $nfi.CurrencyDecimalSeparator = " "
- $myInt.ToString( "C", $nfi )
Technorati Tags: PowerShell,script,formatting,System.Globalization.Cultureinfo,CurrencyDecimalSeparator
Tuesday, 31 August 2010
Get-Cultures.ps1
- <#
- .SYNOPSIS
- This script displays information of cultures on a system.
- .DESCRIPTION
- This script reimplements an MSDN script using PowerShell. It first
- gets the cultures then displays them
- .NOTES
- File Name : Get-Cultures.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/08/get-cultures.html
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.getcultures.aspx
- .EXAMPLE
- PSH [C:\foo]: .\Get-Cultures.ps1'
- CULTURE ISO ISO WIN DISPLAYNAME NATIVENAME
- af af afr AFK Afrikaans Afrikaans
- am am amh AMH Amharic Amharic
- ar ar ara ARA Arabic Arabic
- arn arn arn MPD Mapudungun Mapudungun
- as as asm ASM Assamese Assamese
- az az aze AZE Azeri Azeri
- az-Cyrl az aze AZC Azeri (Cyrillic) Azeri (Cyrillic)
- az-Latn az aze AZE Azeri (Latin) Azeri (Latin)
- ... snipped to save space!
- #>
- # Get Cultures
- $Cultures = [System.Globalization.CultureInfo]::GetCultures([System.Globalization.CultureTypes]::NeutralCultures)
- # Display header then details
- "CULTURE ISO ISO WIN DISPLAYNAME NATIVENAME"
- foreach ($Ci in $Cultures)
- {
- "{0,-8} {1,-3} {2,-3} {3,-3} {4,-40}{4,-40}" -f $Ci.Name,
- $Ci.TwoLetterISOLanguageName,
- $Ci.ThreeLetterISOLanguageName,
- $Ci.ThreeLetterWindowsLanguageName,
- $Ci.DisplayName,
- $Ci.NativeName
- }
Sunday, 28 February 2010
Using-Culture.ps1
Technorati Tags: PowerShell,PowerShell Script,System.Globalization.CultureInfo,System.Threading.Thread,culture
- <#
- .SYNOPSIS
- This script creates a function to run culture sensitive operations
- in some other culture.
- .DESCRIPTION
- The Using-Culture function gets the current culture, saves it, then
- runs the script block in the requested culture. The function then
- restores the culture. The script then ends with calls to
- Using-Culture to demonstrate its use.
- The script is based on a blog note at: http://blogs.msdn.com/powershell/archive/2006/04/25/583235.aspx.
- .NOTES
- File Name : Using-Culture.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 2.0
- .LINK
- This script posted to:
- http://pshscripts.blogspot.com/2010/02/using-cultureps1.html
- .EXAMPLE
- run the script and see!
- #>
- # Defind the Using-Culture function
- Function Using-Culture {
- Param (
- [System.Globalization.CultureInfo]$culture = (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}"),
- [ScriptBlock]$script= (throw "USAGE: Using-Culture -Culture culture -Script {scriptblock}")
- )
- $OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
- trap
- {
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
- }
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
- Invoke-Command $script
- [System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
- }
- ##
- # Now use the function
- ##
- # Here is an example of Using-Culture
- "Get-Date using ar-IQ"
- using-culture ar-IQ {get-date}
- ""
- # Parse ar-IQ formatted date into local culture
- "Parse IQ date to English and display"
- $IQD = "30 تشرين الثاني, 2005 09:01:38 ص"
- using-culture ar-IQ {$global:d=[DateTIme]::Parse($IQD)}
- $IQD
- $d
- ""
- # Now do it in German
- "Get-Date using de-de"
- using-culture de-de {get-date}
- ""
- "Parsing a german date into local"
- $ded="Mittwoch, 30. November 2005 09:02:29"
- using-culture de-de {$global:d=[DateTIme]::Parse($DED)}
- $ded
- $d
Sunday, 13 December 2009
Get-LocaleCurrency.ps1
- <#
- .SYNOPSIS
- This script displays a number formatted in Currency for each locale
- .DESCRIPTION
- This script first creates a value to be formatted, and creates an array
- containing all the locales defined on the system. The script then uses
- each locale to format the value as currency.
- .NOTES
- File Name : Get-LocaleCurrency.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell V2
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- .EXAMPLE
- Left as an exercise for the reader! NB: the output will look better
- is this script is run in PowerShell ISE vs PowerShell console.
- #>
- ##
- # Start of script
- ##
- #Create a value to be formatted
- [int] $Value = 100
- # get all hte locales defined in the system
- $L=[system.Globalization.CultureInfo]::GetCultures('AllCultures') | sort lcid
- foreach ($C in $L) {
- $C=New-Object System.Globalization.CultureInfo $C.Name
- if (!$C.IsNeutralCulture){
- "{0,-50} {1,-6} {2}" -f $C.Displayname,$C.Name,$Value.ToString("C",$c)
- }
- }
Subscribe to:
Posts (Atom)