如何计算非常大的数字? [英] How do I calculate with very large numbers?

查看:155
本文介绍了如何计算非常大的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我一直试图使用的代码。我有一个用户输入textbox1,用户输入一个30位数值,该值需要在末尾添加00。使值为32位。我想对输入值应用除法,并应用其他一些涉及查找余数的计算。但运行时的代码,不断抛出我的值太大或太小的错误。我不知道如何添加截断的答案,我认为这将阻止我收到错误。我不知道该怎么做。任何帮助将不胜感激。非常感谢。

This is my code that I have been attempting to use. I have a user input textbox1, where the user inputs a 30 digit value, that value needs to have '00' added to the end. making the value 32 digits. I want to apply a division to the input value, and apply some other calculations which involve finding the remainder. But the code when run, keeps throwing error that my value is too big or too small. I'm not sure how to add a truncation of the answer which I think will stop me getting the error. I have no idea how to do this. any help would be greatly appreciated. Many thanks.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Windows.Forms;

using System.Text;
using System.IO;

namespace quickcalc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public object Biginteger { get; private set; }

private void button1_Click(object sender, EventArgs e)
{


StreamWriter File = new StreamWriter("Test_File.txt");
//File.WriteLine(textBox1.Text + "00");
//textBox1 = textBox1.Text + "00";
File.WriteLine(textBox1.Text = (Biginteger.Parse(textBox1.Text + "00") / 97).ToString());

File.Close();


}

private void textBox1_TextChanged(object sender, EventArgs e)
{

}
}
}





我尝试了什么:



i尝试过使用'long'函数,但即使抛出与我最初使用的普通int32相同的错误。我不确定如何使用大整数函数作为添加'使用System.Numerics '突出显示它是不必要的。



What I have tried:

i have tried to use the 'long' function but even that threw the same error as my normal int32 which i was using originally. I'm unsure how to use the big integer function as adding the 'using System.Numerics' highlights it as unnecessary.

推荐答案

看看 BigInteger ,请参阅此处的示例: BigInteger Struct(System.Numerics)| Microsoft Docs [ ^ ]



另请参阅此CodeProject示例:计算C#中整数的因子 [ ^ ]
Take a look at BigInteger, see examples here: BigInteger Struct (System.Numerics) | Microsoft Docs[^]

Also see this CodeProject example: Calculate the Factorial of an Integer in C#[^]


这篇关于如何计算非常大的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆