Solved

How to compare 2 more than 30 digit number in java

Posted on 2009-04-08
7
280 Views
Last Modified: 2012-05-11
Can i get the source code or logic to compare 2 more than 30 digit number?
0
Comment
Question by:gunjankhatri
7 Comments
 
LVL 12

Expert Comment

by:basav_com
ID: 24100716
Can you elaborate your question more..
0
 
LVL 25

Accepted Solution

by:
InteractiveMind earned 125 total points
ID: 24100851
Use the java.math.BigInteger class to store your numbers and compare them.
http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24101576
You could turn them both into Strings and compare them with their equals() method.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 1

Expert Comment

by:isarasoo
ID: 24106000
Hi , I have a similar problem to this currently i got around it by loading the digits straight into a char array and then compare the outputs and it works but il rather have a simpler solution.

I tried the above methods suggesting to convert it to string, but that would only be possible if i can store the value as something initially i.e. long  num = 40 digits.

Just a question for InteractiveMind  how many digits can you assign to BigInteger.
sorry in advance if im not allowed to ask a counter question here

thanks
0
 
LVL 1

Expert Comment

by:isarasoo
ID: 24112405
I have just tested bigInteger class and it works fine for numbers over 30dig.  thanks InteractiveMind
0
 
LVL 17

Expert Comment

by:Thomas4019
ID: 24112526
I am fairly sure BigInterger is designed to hold unlimited amount of digitis. It should just keep allocating more memory.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question