Ruby not returning correct dimensions
-
Sorry in advance for what may be a really noob question and I know I've seen this before but been away from scripting for a while and can't remember and can't find the solution by searching...
Basically if I have 3 components in my model each being 1/2" thick when I retrieve the components dimensions in ruby, 2 of them return 0.5 and one returns 0.4999999999999716. Why? and how do my fix that? I did try adding .to_l in my code but that didn't help.
Thanks
-
0.4999999999999716" IS for all intents and purposes 0.5"
All computing code will have some approximation built in to it.
SketchUp's is 1/1000"
That's 0.001"
So quite clearly 0.4999999999999716" is equivalent to 0.5" for all practical purposes.If you need to output the value and you are unhappy with the 'nearness' there are code method to return a user expected 'dim value'...
-
Thanks for the reply and clarification Tig!
The issue I'm having is that I'm using group_by to group by thickness but since the values don't match group_by doesn't work. So knowing what you just explained I'm using 0.4999999999999716.round(6) and that seems to do the trick. I use (6) because some values in inches have six digits after the .
If there's another way fix this issue please let me know.
-
You have found your own solution.
Advertisement