BigInteger.ToString Metoda

Definicja

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu.

Przeciążenia

ToString(String, IFormatProvider)

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu i informacji o formacie specyficznym dla kultury.

ToString(String)

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu.

ToString(IFormatProvider)

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonych informacji formatowania specyficznych dla kultury.

ToString()

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu.

ToString(String, IFormatProvider)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu i informacji o formacie specyficznym dla kultury.

public:
 virtual System::String ^ ToString(System::String ^ format, IFormatProvider ^ provider);
public string ToString (string format, IFormatProvider provider);
public string ToString (string? format, IFormatProvider? provider);
override this.ToString : string * IFormatProvider -> string
Public Function ToString (format As String, provider As IFormatProvider) As String

Parametry

format
String

Standardowy lub niestandardowy ciąg formatu liczbowego.

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu specyficzne dla kultury.

Zwraca

Ciąg reprezentujący bieżącą BigInteger wartość określoną przez format parametry i provider .

Implementuje

Wyjątki

format nie jest prawidłowym ciągiem formatu.

Przykłady

Poniższy przykład inicjuje wartość i wyświetla ją w konsoli przy użyciu standardowego ciągu formatu i NumberFormatInfo obiektu, który definiuje tyldę BigInteger (~) jako znak ujemny.

// Redefine the negative sign as the tilde for the invariant culture.
NumberFormatInfo bigIntegerFormatter = new NumberFormatInfo();
bigIntegerFormatter.NegativeSign = "~";

BigInteger value = BigInteger.Parse("-903145792771643190182");
string[] specifiers = { "C", "D", "D25", "E", "E4", "e8", "F0",
                        "G", "N0", "P", "R", "X", "0,0.000",
                        "#,#.00#;(#,#.00#)" };

foreach (string specifier in specifiers)
   Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier,
                     bigIntegerFormatter));

// The example displays the following output:
//    C: (☼903,145,792,771,643,190,182.00)
//    D: ~903145792771643190182
//    D25: ~0000903145792771643190182
//    E: ~9.031457E+020
//    E4: ~9.0314E+020
//    e8: ~9.03145792e+020
//    F0: ~903145792771643190182
//    G: ~903145792771643190182
//    N0: ~903,145,792,771,643,190,182
//    P: ~90,314,579,277,164,319,018,200.00 %
//    R: ~903145792771643190182
//    X: CF0A55968BB1A7545A
//    0,0.000: ~903,145,792,771,643,190,182.000
//    #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00)
' Redefine the negative sign as the tilde for the invariant culture.
Dim bigIntegerFormatter As New NumberFormatInfo()
bigIntegerFormatter.NegativeSign = "~"

Dim value As BigInteger = BigInteger.Parse("-903145792771643190182")
Dim specifiers() As String = { "C", "D", "D25", "E", "E4", "e8", "F0", 
                               "G", "N0", "P", "R", "X", "0,0.000", 
                               "#,#.00#;(#,#.00#)" }

For Each specifier As String In specifiers
   Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier, 
                     bigIntegerformatter))
Next   
' The example displays the following output:
'    C: (☼903,145,792,771,643,190,182.00)
'    D: ~903145792771643190182
'    D25: ~0000903145792771643190182
'    E: ~9.031457E+020
'    E4: ~9.0314E+020
'    e8: ~9.03145792e+020
'    F0: ~903145792771643190182
'    G: ~903145792771643190182
'    N0: ~903,145,792,771,643,190,182
'    P: ~90,314,579,277,164,319,018,200.00 %
'    R: ~903145792771643190182
'    X: CF0A55968BB1A7545A
'    0,0.000: ~903,145,792,771,643,190,182.000
'    #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00)

Uwagi

Metoda ToString(String, IFormatProvider) formatuje BigInteger wartość w określonym formacie przy użyciu NumberFormatInfo obiektu określonej kultury. Jeśli chcesz użyć formatu dwukierunkowego lub domyślnych ustawień kultury, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Format round-trip ("R") Domyślna (bieżąca) kultura ToString()
Format round-trip ("R") Określona kultura ToString(IFormatProvider)
Określony format Domyślna (bieżąca) kultura ToString(String)

Parametr format może być dowolnym prawidłowym standardowym ciągiem liczbowym lub dowolną kombinacją niestandardowych ciągów formatu liczbowego. Jeśli format wartość jest równa String.Empty lub ma nullwartość , zwracana wartość bieżącego BigInteger obiektu jest formatowana za pomocą specyfikatora formatu dwukierunkowego ("R"). Jeśli format jest inną wartością FormatException, metoda zgłasza wartość .

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Parametr provider jest implementacją IFormatProvider . Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje specyficzne dla kultury dotyczące formatu ciągu zwróconego przez tę metodę. Po wywołaniu ToString(String, IFormatProvider) metody wywołuje provider metodę parametru GetFormat i przekazuje go Type do obiektu reprezentującego NumberFormatInfo typ. Następnie GetFormat metoda zwraca NumberFormatInfo obiekt, który dostarcza informacje dotyczące formatowania parametru value , takiego jak symbol znaku ujemnego, symbol separatora grupy lub symbol separatora dziesiętnego. Istnieją trzy sposoby użycia parametru provider do podawania informacji o formatowaniu do ToString(String, IFormatProvider) metody :

  • Można przekazać obiekt reprezentujący kulturę CultureInfo dostarczającą informacje o formatowaniu. Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje o formatowaniu liczbowym dla tej kultury.

  • Można przekazać rzeczywisty NumberFormatInfo obiekt, który udostępnia informacje o formatowaniu liczbowym. (Jego implementacja GetFormat samego zwraca się).

  • Można przekazać obiekt niestandardowy, który implementuje IFormatProviderelement . Metoda GetFormat tworzy wystąpienie i zwraca NumberFormatInfo obiekt, który dostarcza informacje o formatowaniu.

Jeśli provider parametr ma nullwartość , formatowanie zwracanego ciągu jest oparte na NumberFormatInfo obiekcie bieżącej kultury.

Zobacz też

Dotyczy

ToString(String)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonego formatu.

public:
 System::String ^ ToString(System::String ^ format);
public string ToString (string format);
public string ToString (string? format);
override this.ToString : string -> string
Public Function ToString (format As String) As String

Parametry

format
String

Standardowy lub niestandardowy ciąg formatu liczbowego.

Zwraca

Reprezentacja ciągu bieżącej BigInteger wartości w formacie określonym przez format parametr .

Wyjątki

format nie jest prawidłowym ciągiem formatu.

Przykłady

Poniższy przykład inicjuje BigInteger wartość i wyświetla ją przy użyciu każdego standardowego ciągu formatu i niektórych ciągów formatu niestandardowego.

BigInteger value = BigInteger.Parse("-903145792771643190182");
string[] specifiers = { "C", "D", "D25", "E", "E4", "e8", "F0",
                        "G", "N0", "P", "R", "X", "0,0.000",
                        "#,#.00#;(#,#.00#)" };

foreach (string specifier in specifiers)
   Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier));

// The example displays the following output:
//       C: ($903,145,792,771,643,190,182.00)
//       D: -903145792771643190182
//       D25: -0000903145792771643190182
//       E: -9.031457E+020
//       E4: -9.0314E+020
//       e8: -9.03145792e+020
//       F0: -903145792771643190182
//       G: -903145792771643190182
//       N0: -903,145,792,771,643,190,182
//       P: -90,314,579,277,164,319,018,200.00 %
//       R: -903145792771643190182
//       X: CF0A55968BB1A7545A
//       0,0.000: -903,145,792,771,643,190,182.000
//       #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00)
Dim value As BigInteger = BigInteger.Parse("-903145792771643190182")
Dim specifiers() As String = { "C", "D", "D25", "E", "E4", "e8", "F0", 
                               "G", "N0", "P", "R", "X", "0,0.000", 
                               "#,#.00#;(#,#.00#)" }

For Each specifier As String In specifiers
   Console.WriteLine("{0}: {1}", specifier, value.ToString(specifier))
Next   
' The example displays the following output:
'       C: ($903,145,792,771,643,190,182.00)
'       D: -903145792771643190182
'       D25: -0000903145792771643190182
'       E: -9.031457E+020
'       E4: -9.0314E+020
'       e8: -9.03145792e+020
'       F0: -903145792771643190182
'       G: -903145792771643190182
'       N0: -903,145,792,771,643,190,182
'       P: -90,314,579,277,164,319,018,200.00 %
'       R: -903145792771643190182
'       X: CF0A55968BB1A7545A
'       0,0.000: -903,145,792,771,643,190,182.000
'       #,#.00#;(#,#.00#): (903,145,792,771,643,190,182.00)

Uwagi

Metoda ToString(String) formatuje BigInteger wartość w określonym formacie przy użyciu obiektu reprezentującego NumberFormatInfo konwencje bieżącej kultury. Jeśli chcesz użyć formatu "R" lub rundy albo określić inną kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Format round-trip ("R") Domyślna (bieżąca) kultura ToString()
Format round-trip ("R") Określona kultura ToString(IFormatProvider)
Określony format Określona kultura ToString(String, IFormatProvider)

Parametr format może być dowolnym prawidłowym standardowym ciągiem liczbowym lub dowolną kombinacją niestandardowych ciągów formatu liczbowego. Jeśli format wartość jest równa String.Empty lub ma nullwartość , zwracana wartość bieżącego BigInteger obiektu jest formatowana za pomocą specyfikatora formatu dwukierunkowego ("R"). Jeśli format jest inną wartością FormatException, metoda zgłasza wartość .

Platforma .NET zapewnia rozbudowaną obsługę formatowania, która została szczegółowo opisana w następujących tematach formatowania:

Format zwracanego ciągu jest określany przez NumberFormatInfo obiekt dla bieżącej kultury. W zależności od parametru format ten obiekt kontroluje symbole, takie jak znak ujemny, separator grupy i symbol separatora dziesiętnego w ciągu wyjściowym. Aby zapewnić informacje o formatowaniu dla kultur innych niż bieżąca kultura, wywołaj ToString(String, IFormatProvider) przeciążenie.

Zobacz też

Dotyczy

ToString(IFormatProvider)

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu przy użyciu określonych informacji formatowania specyficznych dla kultury.

public:
 System::String ^ ToString(IFormatProvider ^ provider);
public string ToString (IFormatProvider provider);
public string ToString (IFormatProvider? provider);
override this.ToString : IFormatProvider -> string
Public Function ToString (provider As IFormatProvider) As String

Parametry

provider
IFormatProvider

Obiekt, który dostarcza informacje o formatowaniu specyficzne dla kultury.

Zwraca

Reprezentacja ciągu bieżącej BigInteger wartości w formacie określonym przez provider parametr .

Przykłady

Poniższy przykład tworzy wystąpienie obiektu niestandardowego NumberFormatInfo , który definiuje tyldę (~) jako znak ujemny. Następnie ToString(IFormatProvider) metoda używa obiektu niestandardowego NumberFormatInfo do wyświetlania wartości ujemnej BigInteger .

BigInteger number = 9867857831128;
number = BigInteger.Pow(number, 3) * BigInteger.MinusOne;

NumberFormatInfo bigIntegerProvider = new NumberFormatInfo();
bigIntegerProvider.NegativeSign = "~";

Console.WriteLine(number.ToString(bigIntegerProvider));
Dim number As BigInteger = 9867857831128
number = BigInteger.Pow(number, 3) * BigInteger.MinusOne

Dim bigIntegerProvider As New NumberFormatInfo()
bigIntegerProvider.NegativeSign = "~"      

Console.WriteLine(number.ToString(bigIntegerProvider))

Uwagi

Metoda ToString(IFormatProvider) formatuje BigInteger wartość w formacie "R" lub round-trip przy użyciu NumberFormatInfo obiektu określonej kultury. Jeśli chcesz określić inny format lub bieżącą kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Format round-trip ("R") Domyślna (bieżąca) kultura ToString()
Określony format Domyślna (bieżąca) kultura ToString(String)
Określony format Określona kultura ToString(String, IFormatProvider)

Parametr provider jest implementacją IFormatProvider . Metoda GetFormat zwraca NumberFormatInfo obiekt, który dostarcza informacje specyficzne dla kultury dotyczące formatu ciągu zwróconego przez tę metodę. Jeśli provider ma nullwartość , BigInteger wartość jest formatowana przy użyciu NumberFormatInfo obiektu bieżącej kultury. Jedyną właściwością NumberFormatInfo obiektu, która kontroluje reprezentację BigInteger ciągu wartości przy użyciu specyfikatora formatu ogólnego, jest NumberFormatInfo.NegativeSign, który definiuje znak reprezentujący znak ujemny.

Parametr provider może być jednym z następujących:

Dotyczy

ToString()

Źródło:
BigInteger.cs
Źródło:
BigInteger.cs
Źródło:
BigInteger.cs

Konwertuje wartość liczbową bieżącego BigInteger obiektu na równoważną reprezentację ciągu.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

Zwraca

Reprezentacja ciągu bieżącej BigInteger wartości.

Przykłady

Poniższy przykład przedstawia BigInteger wartość przy użyciu metody domyślnej ToString() . Wyświetla również reprezentacje BigInteger ciągu wartości, która wynika z używania niektórych standardowych specyfikatorów formatu. W przykładach jest używana konwencja formatowania kultury en-US.

// Initialize a BigInteger value.
BigInteger value = BigInteger.Add(UInt64.MaxValue, 1024);

// Display value using the default ToString method.
Console.WriteLine(value.ToString());
// Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G"));
Console.WriteLine(value.ToString("C"));
Console.WriteLine(value.ToString("D"));
Console.WriteLine(value.ToString("F"));
Console.WriteLine(value.ToString("N"));
Console.WriteLine(value.ToString("X"));
// The example displays the following output on a system whose current
// culture is en-US:
//       18446744073709552639
//       18446744073709552639
//       $18,446,744,073,709,552,639.00
//       18446744073709552639
//       18446744073709552639.00
//       18,446,744,073,709,552,639.00
//       100000000000003FF
' Initialize a BigInteger value.
Dim value As BigInteger = BigInteger.Add(UInt64.MaxValue, 1024)

' Display value using the default ToString method.
Console.WriteLine(value.ToString())        
' Display value using some standard format specifiers.
Console.WriteLine(value.ToString("G"))
Console.WriteLine(value.ToString("C"))
Console.WriteLine(value.ToString("D"))
Console.WriteLine(value.ToString("F"))
Console.WriteLine(value.ToString("N"))
Console.WriteLine(value.ToString("X"))       
' The example displays the following output on a system whose current 
' culture is en-US:
'       18446744073709552639
'       18446744073709552639
'       $18,446,744,073,709,552,639.00
'       18446744073709552639
'       18446744073709552639.00
'       18,446,744,073,709,552,639.00
'       100000000000003FF

Uwagi

Metoda ToString() formatuje BigInteger wartość w formacie "R" lub round-trip bieżącej kultury. Jeśli chcesz określić inny format lub kulturę, użyj innych przeciążeń ToString metody w następujący sposób:

Aby użyć formatu Dla kultury Używanie przeciążenia
Format round-trip ("R") Określona kultura ToString
Określony format Domyślna (bieżąca) kultura ToString(String)
Określony format Określona kultura ToString(String, IFormatProvider)

Reprezentacja BigInteger ciągu wartości zawiera znak ujemny, jeśli jego wartość jest ujemna, a sekwencja cyfr od 0 do 9 bez zer wiodących. Znak ujemny jest definiowany NumberFormatInfo przez obiekt dla bieżącej kultury.

Zobacz też

Dotyczy