Click here to Skip to main content
15,884,298 members

How do I calculate with very large numbers?

Member 14042768 asked:

Open original thread
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.
C#
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)
{

}
}
}


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.
Tags: C#

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900