本文整理汇总了C#中System.Numerics.BigInteger.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.ToString方法的具体用法?C# BigInteger.ToString怎么用?C# BigInteger.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.BigInteger
的用法示例。
在下文中一共展示了BigInteger.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatE1
public void FormatE1()
{
var first = new BigInteger(123456789);
Assert.AreEqual(first.ToString("E", CultureInfo.InvariantCulture), "1.234568E+008");
Assert.AreEqual(first.ToString("e", CultureInfo.InvariantCulture), "1.234568e+008");
Debug.Print("BigInteger Format First ok");
var second = BigInteger.Parse("10000009000000001", CultureInfo.InvariantCulture);
Assert.AreEqual(second.ToString("E", CultureInfo.InvariantCulture), "1.000001E+016");
Assert.AreEqual(second.ToString("e", CultureInfo.InvariantCulture), "1.000001e+016");
Debug.Print("BigInteger Format Second ok");
var third = BigInteger.Parse("10000005000000001", CultureInfo.InvariantCulture);
Assert.AreEqual(third.ToString("E", CultureInfo.InvariantCulture), "1.000001E+016");
Assert.AreEqual(third.ToString("e", CultureInfo.InvariantCulture), "1.000001e+016");
Debug.Print("BigInteger Format Third ok");
var fourth = BigInteger.Parse("10000004000000001", CultureInfo.InvariantCulture);
Assert.AreEqual(fourth.ToString("E", CultureInfo.InvariantCulture), "1.000000E+016");
Assert.AreEqual(fourth.ToString("e", CultureInfo.InvariantCulture), "1.000000e+016");
Debug.Print("BigInteger Format Fourth ok");
var fifth = BigInteger.Parse("10000095000000001", CultureInfo.InvariantCulture);
Assert.AreEqual(fifth.ToString("E", CultureInfo.InvariantCulture), "1.000010E+016");
Assert.AreEqual(fifth.ToString("e", CultureInfo.InvariantCulture), "1.000010e+016");
Debug.Print("BigInteger Format Fifth ok");
}
示例2: FormatC
public void FormatC()
{
var first = new BigInteger(123456789);
Assert.AreEqual(first.ToString("C", CultureInfo.InvariantCulture), "¤123,456,789.00");
Assert.AreEqual(first.ToString("c", CultureInfo.InvariantCulture), "¤123,456,789.00");
Assert.AreEqual(first.ToString("C3", CultureInfo.InvariantCulture), "¤123,456,789.000");
Assert.AreEqual(first.ToString("c3", CultureInfo.InvariantCulture), "¤123,456,789.000");
Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("en-US")), "$123,456,789.000");
Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("en-US")), "$123,456,789.000");
Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("fr-FR")), "123\u00A0456\u00A0789,000 €");
Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("fr-FR")), "123\u00A0456\u00A0789,000 €");
Assert.AreEqual(first.ToString("C3", CultureInfo.GetCultureInfo("ja-JP")), "¥123,456,789.000");
Assert.AreEqual(first.ToString("c3", CultureInfo.GetCultureInfo("ja-JP")), "¥123,456,789.000");
var second = BigInteger.Parse("100000090000000010", CultureInfo.InvariantCulture);
Assert.AreEqual(second.ToString("C", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.00");
Assert.AreEqual(second.ToString("c", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.00");
Assert.AreEqual(second.ToString("C3", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.000");
Assert.AreEqual(second.ToString("c3", CultureInfo.InvariantCulture), "¤100,000,090,000,000,010.000");
Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("en-US")), "$100,000,090,000,000,010.000");
Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("en-US")), "$100,000,090,000,000,010.000");
Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("fr-FR")), "100\u00A0000\u00A0090\u00A0000\u00A0000\u00A0010,000 €");
Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("fr-FR")), "100\u00A0000\u00A0090\u00A0000\u00A0000\u00A0010,000 €");
Assert.AreEqual(second.ToString("C3", CultureInfo.GetCultureInfo("ja-JP")), "¥100,000,090,000,000,010.000");
Assert.AreEqual(second.ToString("c3", CultureInfo.GetCultureInfo("ja-JP")), "¥100,000,090,000,000,010.000");
}
示例3: SaddyCopperOperation
private static void SaddyCopperOperation(BigInteger number)
{
if (number.ToString().Length == 1 || numberOfTransformations == 10)
{
if (numberOfTransformations < 10)
{
Console.WriteLine(numberOfTransformations);
}
Console.WriteLine(number);
return;
}
numberOfTransformations++;
List<int> listOfsums = new List<int>();
while (number > 10)
{
number /= 10;
List<int> digitsAtEvenPositions = new List<int>();
for (int i = 0; i < number.ToString().Length; i += 2)
{
digitsAtEvenPositions.Add(number.ToString()[i] - '0');
}
listOfsums.Add(digitsAtEvenPositions.Sum());
}
long product = 1;
foreach (var num in listOfsums)
{
product *= num;
}
//Console.WriteLine(product);
//--------------------------------
SaddyCopperOperation(product);
}
示例4: Run
public string Run()
{
BigInteger total = new BigInteger(0);
for (int i = 1; i <= 1000; i++)
{
total += BigInteger.Pow(i, i);
}
return total.ToString().Substring(total.ToString().Length - 10);
}
示例5: Main
static void Main(string[] args)
{
ulong startNumber = ulong.Parse(Console.ReadLine());
ulong endNumber = ulong.Parse(Console.ReadLine());
string replacementString = Console.ReadLine();
BigInteger sum = new BigInteger();
string sumString = sum.ToString();
//calculate sum of numbers
for (ulong i = startNumber; i < endNumber; i++)
{
if (i % 5 == 0)
{
sum += i;
}
else
{
ulong mod = i % 5;
sum += mod;
}
}
string replacedDigit;
if (sum % 2 == 0)
{
for (int i = 0; i < sumString.Length; i++)
{
replacedDigit = sum.ToString()[0].ToString();
replacedDigit = replacementString;
if (sumString[i].Equals(replacedDigit))
{
string newString = sumString[i].ToString();
newString = replacementString;
}
}
}
else
{
for (int i = 0; i < sumString.Length; i++)
{
replacedDigit = sum.ToString()[sum.ToString().Length - 1].ToString();
replacedDigit = replacementString;
if (sumString[i].Equals(replacedDigit))
{
string newString = sumString[i].ToString();
newString = replacementString;
}
}
}
Console.WriteLine(sumString);
}
示例6: is_prime_MR
private static bool is_prime_MR(BigInteger R, int num)
{
Random random = new Random();
BigInteger s = 0;
BigInteger t = R - 1;
while (t % 2 == 0)
{
t = t / 2;
s++;
}
String st = "";
int p;
int q = Int32.MaxValue;
BigInteger A;
BigInteger b;
BigInteger i = 0;
for (int j = 1; j <= num; j++)
{
p = random.Next(10);
if (p % 2 == 0)
p = p + 1;
st = p.ToString();
while (st.Length <= R.ToString().Length - q.ToString().Length)
{
st = random.Next(q) + st;
}
try
{
st = random.Next(10 ^ (R.ToString().Length - st.Length - 2)) + st;
}
catch { }
A = BigInteger.Parse(st);
if (A.IsOne)
A++;
if ((R % A).IsZero)
return false;
b = BigInteger.ModPow(A, t, R);
if (b.IsOne)
continue;
i = 0;
do
{
b = BigInteger.ModPow(b, BigInteger.One + BigInteger.One, R);
i++;
}
while (!(b.IsOne || b.ToString() == (R - 1).ToString() || i > s));
if (i > s)
return false;
}
return true;
}
示例7: Main
static void Main(string[] args)
{
short n = 1000;
var bi = new BigInteger();
for (short i = 1; i <= n; i++)
bi += Pow(i, i);
Console.WriteLine(bi.ToString().Substring(bi.ToString().Length-10, 10));
Console.ReadKey();
}
示例8: ConvertToArray
private static int[] ConvertToArray(BigInteger num)
{
int[] digits = new int[num.ToString().Length];
string number = num.ToString();
BigInteger currentNumber = num;
for (int i = number.Length - 1; i >= 0; i--)
{
digits[i] = (int)(currentNumber % 10);
currentNumber /= 10;
}
return digits;
}
示例9: Calculate
private void Calculate()
{
BigInteger res = new BigInteger();
res = a + b;
textBox3.Text = res.ToString();
res = a * b;
textBox4.Text = res.ToString();
res = BigInteger.Pow(a, 2);
textBox5.Text = res.ToString();
res = BigInteger.ModPow(a, 1, b);
textBox6.Text = res.ToString();
}
示例10: ConvertToArray
// Convert number of digit to array
static int[] ConvertToArray(BigInteger num)
{
string digit = num.ToString();
int[] digits = new int[num.ToString().Length];
int count = 0;
foreach (var item in digit)
{
digits[count] = item - '0';
count++;
}
return digits;
}
示例11: IsLychrel
static bool IsLychrel(BigInteger nn)
{
int attempts = 50;
do
{
nn += BigInteger.Parse(Util.ReverseString(nn.ToString()));
if (Util.IsPalindrome(nn.ToString()))
{
return false;
}
} while (attempts-- > 0);
return true;
}
示例12: CalculateProduct
public static BigInteger CalculateProduct(BigInteger firstMultiplier, BigInteger secondMultiplier)
{
int n = firstMultiplier.ToString().Length;
a = BigInteger.Parse(firstMultiplier.ToString().Substring(0, n / 2));
b = BigInteger.Parse(firstMultiplier.ToString().Substring(n / 2));
c = BigInteger.Parse(secondMultiplier.ToString().Substring(0, n / 2));
d = BigInteger.Parse(secondMultiplier.ToString().Substring(n / 2));
BigInteger ac = a * c;
BigInteger bd = b * d;
return BigInteger.Pow(10, n) * ac + BigInteger.Pow(10, n / 2) * ((a + b) * (c + d) - ac - bd) + bd;
}
示例13: FormatD
public void FormatD()
{
var first = new BigInteger(123456789);
Assert.AreEqual(first.ToString("D", CultureInfo.InvariantCulture), "123456789");
Assert.AreEqual(first.ToString("d", CultureInfo.InvariantCulture), "123456789");
Assert.AreEqual(first.ToString("D20", CultureInfo.InvariantCulture), "00000000000123456789");
Assert.AreEqual(first.ToString("d20", CultureInfo.InvariantCulture), "00000000000123456789");
var second = BigInteger.Parse("100000090000000010", CultureInfo.InvariantCulture);
Assert.AreEqual(second.ToString("D", CultureInfo.InvariantCulture), "100000090000000010");
Assert.AreEqual(second.ToString("d", CultureInfo.InvariantCulture), "100000090000000010");
Assert.AreEqual(second.ToString("D20", CultureInfo.InvariantCulture), "00100000090000000010");
Assert.AreEqual(second.ToString("d20", CultureInfo.InvariantCulture), "00100000090000000010");
}
示例14: GetAnswer
public override string GetAnswer()
{
BigInteger pectorial = new BigInteger(1);
for (int i=1; i<=100; i++) {
pectorial *= i;
}
int result = 0;
foreach (char c in pectorial.ToString().ToArray()) {
result += c - 48;
}
return string.Format("결과값 {0} 의 자리수를 모두 더한 값 : {1}", pectorial.ToString(), result);
}
示例15: ShortenCurrency
public static string ShortenCurrency(this string String, BigInteger Currency)
{
if (Currency < 1000000) return Currency.ToString("#,##0");
else
{
string currencyString = Currency.ToString();
int currencyStringLength = currencyString.Length;
double calculation = (currencyStringLength / 3d);
int baseNumberLength = ((calculation == (int)calculation) ? 3 : (int)Math.Round((calculation - (int)calculation) * 3));
string decimals = currencyString.Substring(baseNumberLength, Math.Min(3, (currencyStringLength - baseNumberLength))).TrimEnd('0');
return String = (currencyString.Substring(0, baseNumberLength) +
((decimals.Length > 0) ? ("." + decimals) : null)
+ " " + CurrencyNames[(int)Math.Ceiling(calculation) - 3]);
}
}