File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double calculation

 
Y Cheong
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very frequently asked question. See here for a recent good answer.
 
praveen kumar gudapati
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic