?
Solved

How to compare 2 more than 30 digit number in java

Posted on 2009-04-08
7
Medium Priority
?
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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.
Suggested Courses

649 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