File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Double comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Double comparison" Watch "Double comparison" New topic
Author

Double comparison

Waez Ali
Ranch Hand

Joined: Jan 24, 2005
Posts: 43
Hi,

I have requirement to check following

value1 = "99999999999.00"
value2 = "123122.55";

double d1 = Double.parse(value1) ;
double d2 = Double.parse(value2) ;

if(d1>d2){
sop("Big")
}
else{
sop("small")
}

Expected output is Big but giving me small.

I tried to print their values & its making 9.99999991E something when I use double parse option.

Can someone help me in comparing these big values ?
Waez Ali
Ranch Hand

Joined: Jan 24, 2005
Posts: 43
I got the answer from google,

java.util.math.BegDecimal
Paul Beckett
Ranch Hand

Joined: Jun 14, 2008
Posts: 96
I've tried the example code you provided (changed parse to parseDouble to make it compile) and it works fine i.e. prints out big.

Is the code you were using exactly like the example you've shown?

I recommend the use of BigDecimal if you are going to be comparing the values of large doubles. It will take a String as a contructor argument and has compareTo or a max method that will provide the functionality you require.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
http://faq.javaranch.com/java/PostRealCode


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Double comparison
 
Similar Threads
adding big decimal numbers
Double Boolean Operations
Math.min with "-0" and "+0"
Double / Float Doubt.
Increase the range of Double