Okay, I just typed a big long reply about this that didn't get posted and was lost, so here's something close:
In SolidWorks, numbers are stored internally in a base 2 floating point format (probably double precision IEEE because that's what's exposed in all their API calls) which has inherent limitations in the accuracy of computation. Actually our base 10 representation also has errors, but we don't notice those so much, and when the computer produces a different answer from the "obvious" base 10 approach we cry foul. For example, one tenth (0.1) does not have a finite representation in base
- So if you add it together 10 times, you get a number slightly less than one. Try this in a macro:
x = 0.1 MsgBox 1 - (x + x + x + x + x + x + x + x + x + x)
What's that? 1x10^-16 or so? So you see that it's not quite 1. This is a little problem because in the UI it's impractical to show
0.999999999999999, so it just shows 1. But then you call the integer function on that number, and you get zero because that's what's stored internally. It's not a bug in SolidWorks, but it is just one of the limits of numerical computation.
You can't eliminate this error, but there are some principles and methods you can follow to reduce it. For more information on the binary representation as well as a few good links at the bottom, look at
formatting link
may also try searching on numerical analysis.
Jonathan Anderson