wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes double calculation 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 calculation" Watch "double calculation" New topic
Author

double calculation

Y Cheong
Greenhorn

Joined: Jan 19, 2003
Posts: 9
Hi
I have the following variables:
double a = 56.03;
double b = 38;
double c = 16.3;
For the following calculation
double d = a - (b + c)
This should give 1.73, however when I print out d- this gives 1.730000000000004. Please can anyone solve this.
Thanks
Y
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This is a very frequently asked question. See here for a recent good answer.


[Jess in Action][AskingGoodQuestions]
praveen kumar gudapati
Greenhorn

Joined: Sep 26, 2003
Posts: 15
double a = 56.03;
double b = 38;
double c = 16.3;
double d = 0;
NumberFormat formatter = NumberFormat.getInstance();
d = a - (b + c);
formatter.format(d);
try this,
Good luck
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: double calculation
 
Similar Threads
Difference between notify and notifyAll
Converting BigDecimal to double
Math
Kathy's book - chapter 6 - question #7
does == count as arithmetic calculation?