sum "product of double type" calculation not percise

public class Test3 {

public static void main(String[] args) {

double weight[][] = {

{ 0.0, 1.0, -3.0, 2.0, -0.3, -2.1, -1.0},

{ 1.0, 0.0, 1.0, 1.0, 3.0, -4.0, 0.0},

{-3.0, 1.0, 0.0, 0.0, 1.0, -1.0, -1.0},

{ 2.0, 1.0, 0.0, 0.0, 0.0, -2.4, 3.3},

{-0.3, 3.0, 1.0, 0.0, 0.0, 1.0, 1.0},

{-2.1, -4.0, -1.0, -2.4, 1.0, 0.0, -1.0},

{ 1.0, 0.0, -1.0, 3.3, 1.0, -1.0, 0.0}

};

double input[] = {1.000000 ,-1.000000 ,1.000000 ,-1.000000 ,1.000000 ,-1.000000 ,1.000000};

double sum = 0.0;

for (int i = 0; i < 7; i++ ){

sum = 0.0;

for (int j = 0; j < 7; j++ ){

sum += weight[j] * input[j];

}

System.out.println("sum " + i + " = " + sum);

}

}

}

I get the result as below

sum 0 = -5.199999999999999

sum 1 = 8.0

sum 2 = -3.0

sum 3 = 6.699999999999999

sum 4 = -2.3

sum 5 = 3.3

sum 6 = -1.2999999999999998

how come?

It suppose

sum 0 = -5.2

sum 3 = 6.7

sum 6 = -1.3

[1069 byte] By [haley_china] at [2007-11-26 13:11:13]
# 1
http://docs.sun.com/source/806-3568/ncg_goldberg.htmlCongratulation, you're the 43276324th person wondering about this.
CeciNEstPasUnProgrammeura at 2007-7-7 17:26:26 > top of Java-index,Java Essentials,Java Programming...
# 2
Sun also has a tech tip article that talks about doing floating point arithmetic: http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2
hungyee98a at 2007-7-7 17:26:26 > top of Java-index,Java Essentials,Java Programming...