System.Globalization.NumberFormatInfo.PercentNegativePattern Property

Gets or sets the format pattern for negative percent values.

Syntax

public int PercentNegativePattern { get; set; }

Value

A int between 0 and 2 inclusive that specifies the format of negative percent values.

Exceptions

TypeReason
ArgumentOutOfRangeExceptionThe value specified for a set operation is less than 0 or greater than 2.
InvalidOperationExceptionThe current instance is read-only and a set operation was attempted.

Remarks

The NumberFormatInfo.PercentNegativePattern property is used with the "P" standard format string to define the pattern of negative percentage values. For more information, see Standard Numeric Format Strings. This property has one of the values in the following table. The symbol "%" is the NumberFormatInfo.PercentSymbol, the symbol "-" is the NumberFormatInfo.NegativeSign, and n is a number. Values 3-11 were introduced in the .NET Framework 2.0 and cannot be used in earlier versions.

0

-n %

1

-n%

2

-%n

3

%-n

4

%n-

5

n-%

6

n%-

7

-% n

8

n %-

9

% n-

10

% -n

11

n- %

Example

The following example demonstrates the effects of different NumberFormatInfo.PercentNegativePattern property values.

C# Example

using System;
using System.Globalization;
class Test {
 public static void Main() {
 NumberFormatInfo nfi = new NumberFormatInfo();
 decimal data = -.9900m;
 for (int i = 0; i<=2 ; i++) {
 nfi.PercentNegativePattern = i;
 Console.WriteLine("pattern # {0}: {1}",i,data.ToString("P",nfi));
 }
 }
}
   

The output is

pattern # 0: -99.00 %
pattern # 1: -99.00%
pattern # 2: -%99.00

Requirements

Namespace: System.Globalization
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0