0
How can I store a big number? for example I want to store the 100000000 ! and I want it in my calculation
13 Réponses
+ 8
use BigInteger .Heres complete detail :-
https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html
Also, Check out my code :-
https://code.sololearn.com/c78uTK8OaL4w/?ref=app
+ 7
Use BigInteger. Here's a small tutorial.
https://code.sololearn.com/WS60ll19CFej/?ref=app
+ 6
Keep in mind that if you use strings each digit in number will take 1 byte of memory. So if you got a number with 1000000000 digits you should find a 1 gb of RAM to store it.
+ 5
use long integer or reference data type..
+ 5
use datatype of long, you can store that number.
Else, you can use string.
+ 4
Anytime bro, @SaraBolouri
+ 4
use the data type "long" if the number is too big for an int. max number for long is like 9.4 quintillion, so if the number is bigger than that, use the BigInteger class
+ 2
@Meharban Singh tnx a lot ... your code is very good for me
+ 1
Dislike? Am I wrong? If yes I would love to hear where :)
+ 1
@Jeth Never thought of that, thanks for teaching me something new :o
+ 1
@Jeth l mean,not digits...my number is 1000000000,not the number of digits....but tax for teaching
0
Store it as a string, I had the similar task where I had to add two numbers that were out of bonds of int and long. The way I did it is that I stored the number as a string, and added up each digits of the numbers indvidualy, kind of like kids do it in elementary school
12345 +
05678
-------------
18023
Edit: @Krishna 's way works, but it still has a limited range of numbers it accepts where as this way doesn't. Keep in my by doing it this way you can't really do complex stuff efficiently.
- 1
use data type "long"