You are doing this fine. The problem is with the inaccuracy of floating point numbers.
Why are floating point numbers so inaccurate?
If you wish to display this number then use:
heights[i].toFixed(2);
Note that toFixed() returns a string and you will have to convert back to a float (parseFloat()) if you want to perform more numerical operations.