# double calculation

Y Cheong

Greenhorn

Posts: 9

posted 12 years ago

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

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

praveen kumar gudapati

Greenhorn

Posts: 15

posted 12 years ago

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

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