Solved

How to compare 2 more than 30 digit number in java

Posted on 2009-04-08
7
283 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 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

705 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