• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Double comparison

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer from google,

java.util.math.BegDecimal
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/PostRealCode
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic