當前位置: 首頁>>代碼示例>>C#>>正文


C# BigInteger.ToString方法代碼示例

本文整理匯總了C#中System.Numerics.BigInteger.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# BigInteger.ToString方法的具體用法?C# BigInteger.ToString怎麽用?C# BigInteger.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Numerics.BigInteger的用法示例。


在下文中一共展示了BigInteger.ToString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1:

// 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
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:21,代碼來源:BigInteger.ToString

示例2: NumberFormatInfo

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

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

Console.WriteLine(number.ToString(bigIntegerProvider));
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:7,代碼來源:BigInteger.ToString

示例3: foreach

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));
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:7,代碼來源:BigInteger.ToString

輸出:

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)

示例4: NumberFormatInfo

// 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));
開發者ID:.NET開發者,項目名稱:System.Numerics,代碼行數:12,代碼來源:BigInteger.ToString

輸出:

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)


注:本文中的System.Numerics.BigInteger.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。