Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

confusion in double operations...

 
Vishal K Patel
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


o/p : 20.79



o/p : 20.889999999999997

i think in 2nd case o/p should be 20.89...!!!
and actually i want the o/p 20.89.
what could be done..?

help me out...
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Use printf():



or you can use:



Thanks,
[ May 30, 2007: Message edited by: Chandra Bhatt ]
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is ok....But why is it happening so??

I mean,

why is it not 2.89 in 2nd case?
and why is it different in fist case?
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one take a look at this?
Please.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prasad Tamirisa:
Can any one take a look at this?
Please.


Tried Google for "floating point arithmetic accuracy" or similar? You will find discussions of floating point arithmetic accuracy in an elementary numerical mathematics course book.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow....! Thats a great reference.

Thanks once again barry. You have been so helpful to me these days.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Prasad Tamirisa:
Wow....! Thats a great reference.

Thanks once again barry. You have been so helpful to me these days.


Yes, I like to help people with initiative
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic