• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Ruby not returning correct dimensions

Scheduled Pinned Locked Moved Developers' Forum
4 Posts 2 Posters 1.3k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    Frankn
    last edited by 14 Jul 2017, 17:04

    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

    1 Reply Last reply Reply Quote 0
    • T Online
      TIG Moderator
      last edited by 14 Jul 2017, 17:29

      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'...

      TIG

      1 Reply Last reply Reply Quote 0
      • F Offline
        Frankn
        last edited by 17 Jul 2017, 22:46

        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.

        1 Reply Last reply Reply Quote 0
        • T Online
          TIG Moderator
          last edited by 18 Jul 2017, 09:15

          You have found your own solution.
          😉

          TIG

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            4/4
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement