Answer the question
In order to leave comments, you need to log in
How to store and perform operations on a large number of type int?
There is a type variable decimal
; it has its own limit and at some point, when subtracting a smaller number, it goes into a negative value. Is there any other way to store a very large integer and perform mathematical operations on it. I'm new to Unity and C#, if it's not difficult, tell me more. If you need sources, write, I will share.
Number example: 91948102834320102834715231012347
This is the maximum value.
Answer the question
In order to leave comments, you need to log in
the easiest option is to use BigInteger
using System;
using System.Numerics;
public class Program
{
public static void Main()
{
BigInteger hugeInt = BigInteger.Parse("91948102834320102834715231012347");
Console.WriteLine(hugeInt);
}
}
Alternatively, you can implement algorithms for working with long numbers yourself. A branch of computer science is called long arithmetic. brestprog.by/topics/longarithmetics
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question