Freigeben über


NumberFormatInfo.PercentPositivePattern Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the format pattern for positive percent values.

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Property PercentPositivePattern As Integer
public int PercentPositivePattern { get; set; }

Property Value

Type: System.Int32
The format pattern for positive percent values. The default for InvariantInfo is 0, which represents "n %", where "%" is the PercentSymbol and n is a number.

Exceptions

Exception Condition
ArgumentOutOfRangeException

The property is being set to a value that is less than 0 or greater than 3.

InvalidOperationException

The property is being set and the NumberFormatInfo object is read-only.

Remarks

This property has one of the values in the following table. The symbol "%" is the PercentSymbol and n is a number.

Value

Associated pattern

0

n %

1

n%

2

%n

3

% n

Examples

The following example formats a numeric value using each of the four possible values of the PercentPositivePattern property for the current culture.

Imports System.Globalization

Public Module Example
   Public Sub Demo(outputBlock As System.Windows.Controls.TextBlock)
      ' Create a read-write NumberFormatInfo object for the current culture.
      Dim numberInfo As NumberFormatInfo = DirectCast(NumberFormatInfo.CurrentInfo.Clone, _
                                                      NumberFormatInfo)
      Dim value As Decimal = 0.1324d

      ' Assign each possible value to the PercentPositivePattern property.
      For ctr As Integer = 0 to 3
         numberInfo.PercentPositivePattern = ctr
         outputBlock.Text += String.Format("{0}: {1}", _
                                           ctr, value.ToString("P", numberInfo)) + vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'       0: 13.24 %
'       1: 13.24%
'       2: %13.24
'       3: % 13.24
using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Create a read-write NumberFormatInfo object for the current culture.
      NumberFormatInfo numberInfo = NumberFormatInfo.CurrentInfo.Clone() as NumberFormatInfo;
      decimal value = 0.1324m;

      // Assign each possible value to the CurrencyNegativePattern property.
      for (int ctr = 0; ctr <= 3; ctr++)
      {
         numberInfo.PercentPositivePattern = ctr;
         outputBlock.Text += String.Format("{0}: {1}\n", ctr, 
                                           value.ToString("P", numberInfo));
      }
   }
}
// The example displays the following output:
//        0: -13.24 %
//        1: -13.24%
//        2: -%13.24
//        3: %-13.24
//        4: %13.24-
//        5: 13.24-%
//        6: 13.24%-
//        7: -% 13.24
//        8: 13.24 %-
//        9: % 13.24-
//       10: % -13.24
//       11: 13.24- %

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.