NumberFormatInfo.NumberNegativePattern Propriedade

Definição

Obtém ou define o padrão de formato para valores numéricos negativos.

public:
 property int NumberNegativePattern { int get(); void set(int value); };
public int NumberNegativePattern { get; set; }
member this.NumberNegativePattern : int with get, set
Public Property NumberNegativePattern As Integer

Valor da propriedade

Int32

O padrão de formato para valores numéricos negativos.

Exceções

A propriedade está sendo definida como um valor menor que 0 ou maior que 4.

A propriedade está sendo definida e o objeto NumberFormatInfo é somente leitura.

Exemplos

O exemplo a seguir exibe um valor usando NumberNegativePattern padrões diferentes.

using namespace System;
using namespace System::Globalization;

int main()
{
   // Create a new NumberFormatinfo.
   NumberFormatInfo^ nfi = gcnew NumberFormatInfo;
   
   // Takes a negative value.
   Int64 value = -1234;
   
   // Displays the value with default formatting.
   Console::WriteLine("{0,-20} {1,-10}", "Default:", 
                          value.ToString("N", nfi));
   
   // Displays the value with other patterns.
   for (int i = 0; i <= 4; i++) {
      nfi->NumberNegativePattern = i;
      Console::WriteLine("{0,-20} {1,-10}", 
                              String::Format("Pattern {0}:", 
                                             nfi->NumberNegativePattern), 
                              value.ToString("N", nfi));
   }
}
// The example displays the following output:
//       Default:             -1,234.00
//       Pattern 0:           (1,234.00)
//       Pattern 1:           -1,234.00
//       Pattern 2:           - 1,234.00
//       Pattern 3:           1,234.00-
//       Pattern 4:           1,234.00 -
 using System;
 using System.Globalization;

 class Example
 {
     public static void Main()  {

       // Create a new NumberFormatinfo.
       NumberFormatInfo nfi = new NumberFormatInfo();

       // Define a negative value.
       Int64 value = -1234;

       // Display the value with default formatting.
        Console.WriteLine("{0,-20} {1,-10}", "Default:",
                          value.ToString("N", nfi));

       // Display the value with other patterns.
       for (int i = 0; i <= 4; i++)  {
          nfi.NumberNegativePattern = i;
            Console.WriteLine("{0,-20} {1,-10}",
                              string.Format("Pattern {0}:",
                                            nfi.NumberNegativePattern),
                              value.ToString("N", nfi));
       }
   }
}
// The example displays the following output:
//       Default:             -1,234.00
//       Pattern 0:           (1,234.00)
//       Pattern 1:           -1,234.00
//       Pattern 2:           - 1,234.00
//       Pattern 3:           1,234.00-
//       Pattern 4:           1,234.00 -
Imports System.Globalization

Module Example
    Public Sub Main()
        ' Creates a new NumberFormatinfo.
        Dim nfi As New NumberFormatInfo()
        
        ' Define a negative value.
        Dim value As Int64 = -1234
        
        ' Display the value with default formatting.
        Console.WriteLine("{0,-20} {1,-10}", "Default:", 
                          value.ToString("N", nfi))
        
        ' Display the value with other patterns.
        For i As Integer = 0 To 4
            nfi.NumberNegativePattern = i
            Console.WriteLine("{0,-20} {1,-10}", 
                              String.Format("Pattern {0}:", 
                                            nfi.NumberNegativePattern), 
                              value.ToString("N", nfi))
        Next 
    End Sub
End Module
' The example displays the following output:
'       Default:             -1,234.00
'       Pattern 0:           (1,234.00)
'       Pattern 1:           -1,234.00
'       Pattern 2:           - 1,234.00
'       Pattern 3:           1,234.00-
'       Pattern 4:           1,234.00 -

Comentários

A NumberNegativePattern propriedade define o formato dos valores negativos formatados com a cadeia de caracteres de formato numérico padrão "N". Essa propriedade tem um dos valores na tabela a seguir. O símbolo "-" é o NegativeSign e n é um número.

Valor Padrão associado
0 p
1 -n
2 -n
3 -
4 p

O valor padrão para a cultura invariável retornado pela InvariantInfo propriedade é 1, que representa "-n", em que n é um número.

Aplica-se a

Confira também