0

I have an array of type double storing 3 values I want to increment the value by 3 cents but I get a bunch of decimal places I can't seem to figure out what the problem is

double [] cupsPrice = {0.93, 1.65, 2.77};    
for(int i=0; i<7; i++){
    for(int l=0; l<3; l++){
        cupsPrice[l] += 0.03;
    }
}////expecting 0.96 in second run but is returning 0.0960000000000001
joanb
  • 169
  • 1
  • 1
  • 17
  • Read up on floating point arithmetic.http://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate – wickstopher May 17 '15 at 04:46
  • This is normal behaviour for floating point arithmetic ... in all mainstream programming languages. – Stephen C May 17 '15 at 04:47

0 Answers0