NumberFormatInfo.CurrencyDecimalSeparator Property
.NET Framework 4
Gets or sets the string to use as the decimal separator in currency values.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.StringThe string to use as the decimal separator in currency values. The default for InvariantInfo is ".".
| Exception | Condition |
|---|---|
| ArgumentNullException |
The property is being set to null. |
| InvalidOperationException |
The property is being set and the NumberFormatInfo is read-only. |
| ArgumentException |
The property is being set to an empty string. |
The following example demonstrates the effect of changing the CurrencyDecimalSeparator property.
using System; using System.Globalization; class NumberFormatInfoSample { public static void Main() { // Gets a NumberFormatInfo associated with the en-US culture. NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat; // Displays a value with the default separator ("."). Int64 myInt = 123456789; Console.WriteLine( myInt.ToString( "C", nfi ) ); // Displays the same value with a blank as the separator. nfi.CurrencyDecimalSeparator = " "; Console.WriteLine( myInt.ToString( "C", nfi ) ); } } /* This code produces the following output. $123,456,789.00 $123,456,789 00 */
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
CurrencyDecimalSeparator sample - reimplemented using PowerShell
<#
.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 )
- 11/1/2011
- Thomas Lee