Click here to Skip to main content
14,357,676 members
Rate this:
Please Sign up or sign in to vote.
See more:
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)
{

}
}
}


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.
Posted
Updated 10-Mar-19 11:42am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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#[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100