This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "double calculation" Watch "double calculation" New topic

double calculation

Y Cheong

Joined: Jan 19, 2003
Posts: 9
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.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

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

[Jess in Action][AskingGoodQuestions]
praveen kumar gudapati

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);
try this,
Good luck
I agree. Here's the link:
subject: double calculation
jQuery in Action, 3rd edition