1

I declared a single array of size 100 and stored some 6 values in it. I then transferred them to a different Excel workbook. However, when they were transferred they were given extra digits well past their last decimal.

Ex: 1.1, when stored then transferred, gave a value of 1.10000002384185.

I changed the array type to double and it fixed it, but I'm just curious as to what was happening.

Dim Program_LC_Array(100) As Single
Dim y As Long
Dim x As Long

With Workbooks("Workbook1").Sheets("Program")
For x = 2 To 7
    Program_LC_Array(y) = .Range("M" & x).Value
    y = y + 1
Next x
y = y - 1
End With

With Workbooks("Workbook2").Sheets("Destination")
For x = 0 To y
    .Range("A" & x).Value = Program_LC_Array(x)
Next x
End With

Poppenhoffer
  • 39
  • 1
  • 7
  • How should we know what is happening? We don't have any means of seeing the data or the function `Program_LC_Array()`. Maybe it is just a formatting problem in the spreadsheet itself. Maybe it is another example of [Is floating point math broken?](https://stackoverflow.com/q/588004/4996248) – John Coleman Dec 05 '19 at 19:22
  • Side note - you don't need arrays here. You can transfer values from one range to another (though I'm guessing you know this). – BigBen Dec 05 '19 at 19:26
  • Yeah, the rest of the code is pages long. It needs to be an array for a few reasons. I think the aforementioned floating point math is the problem. I was just curious. – Poppenhoffer Dec 05 '19 at 19:35
  • when you changed to `double` the value is actually `1.10` , not `1.1` but because the last number is a zero, i assume your excel formats remove any trailing zeros.. – alowflyingpig Dec 05 '19 at 19:38

0 Answers0