I declared a long in Java code and it only take 19 decimal digits. I need a data type that takes over 300 decimal digits.
Asked
Active
Viewed 156 times
-3
-
1In the future, mark this as java. javascript and java are not the same. – goatofanerd Aug 23 '21 at 20:26
-
1And also, what is this for? You might be able to use a string, but tough to say without more info – goatofanerd Aug 23 '21 at 20:27
-
1*how to use large number in java like 300 decimal digit or more?* - What will you use it for? – Arvind Kumar Avinash Aug 23 '21 at 20:28
-
Using a string to represent large numbers is a popular approach in any programming languages. But you may need to implement the operations you may need for your new string number class. Such as add, subtract, or etc as needed. – Ashkanxy Aug 23 '21 at 20:32
-
Perhaps [`BigDecimal`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/math/BigDecimal.html). – Basil Bourque Aug 23 '21 at 20:33
-
@goatofanerd I need decimal values because i will use it to RSA algorithm program – Amr Alasmer Aug 23 '21 at 21:27
-
@ArvindKumarAvinash RSA algorithm program – Amr Alasmer Aug 23 '21 at 21:27
-
@BasilBourque BigDecimal is not big enough it's like 80 digit – Amr Alasmer Aug 23 '21 at 21:29
-
@AmrAlasmer - BigDecimal can cope with numbers with *billions* of digits ... if you have enough RAM. – Stephen C Aug 24 '21 at 00:12
-
But if you are trying to implement RSA, you probably want `BigInteger`. Because RSA is defined in terms of integers rather than "decimal values". Anyway, look at the javadocs and the duplink. – Stephen C Aug 24 '21 at 00:13
1 Answers
0
There is no primitive type that supports a number that long.
What you are searching for is most likely a BigInteger object. Calculations are done through the methods shown in the API.
As another user said, Javascript and Java are two different languages, please use the correct tag.

WingsOfDespair
- 1
- 2