sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Is there a ceiling function like in excel?

    Scheduled Pinned Locked Moved Developers' Forum
    20 Posts 5 Posters 5.2k Views 5 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
      Frankn
      last edited by

      Wow! Thanks for taking the time to explain it in a Ruby's for Dummies term! πŸ˜„ No way I would of come up with a solution to that problem!

      That now makes total sense... now I'm off to try and implement this in my script... should fun πŸ˜„

      Thanks again!

      1 Reply Last reply
      Reply Quote 0
      • J
        Jim
        last edited by

        my_num = 0.17578125 frac = 16.0 # 1/16th (radix, specifically) rounded_num = (my_num * frac).round / frac

        Hi

        1 Reply Last reply
        Reply Quote 0
        • Chris FullmerC
          Chris Fullmer
          last edited by

          That can't be right, you didn't even have to make any special methods to do that 😳 πŸ˜†

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply
          Reply Quote 0
          • Dan RathbunD
            Dan Rathbun
            last edited by

            This is for measurements?

            One limitation within Sketchup, is that the precision is limited to 0.001", no matter what the model units are set to.

            So using a fractional float of 0.1875" may get rounded by Sketchup. Will it be 0.187" or 0.188" ??
            I would suggest that you decide what it will be in your 'rounding' method...

            I'm not here much anymore.

            1 Reply Last reply
            Reply Quote 0
            • J
              Jim
              last edited by

              @Chris -Been there - just passing it along.

              Hi

              1 Reply Last reply
              Reply Quote 0
              • TIGT
                TIG Moderator
                last edited by

                Here's Jim's clever solution made into a method...

                def roundtofraction(num, frac)
                  num = num.to_f
                  frac = frac.to_f
                  return (num * frac).round / frac
                end
                

                Usage:
                my_num = 0.17578125
                my_frac = 16
                my_num=roundtofraction(my_num, my_frac)

                0.1875

                TIG

                1 Reply Last reply
                Reply Quote 0
                • F
                  Frankn
                  last edited by

                  @jim said:

                  my_num = 0.17578125 frac = 16.0 # 1/16th (radix, specifically) rounded_num = (my_num * frac).round / frac

                  Dude you're a genius! That is awesome!

                  Thank you!!

                  1 Reply Last reply
                  Reply Quote 0
                  • F
                    Frankn
                    last edited by

                    @chris fullmer said:

                    That can't be right, you didn't even have to make any special methods to do that 😳 πŸ˜†

                    Chris don't feel bad even after doing this thing called 'programming' for the last few weeks I'm still getting the hang of methods, classes and all that jazz!! 😳 πŸ˜†

                    1 Reply Last reply
                    Reply Quote 0
                    • F
                      Frankn
                      last edited by

                      @dan rathbun said:

                      This is for measurements?

                      One limitation within Sketchup, is that the precision is limited to 0.001", no matter what the model units are set to.

                      So using a fractional float of 0.1875" may get rounded by Sketchup. Will it be 0.187" or 0.188" ??
                      I would suggest that you decide what it will be in your 'rounding' method...

                      Yes Dan, this is for measurements.

                      I didn't know that limitation about Sketchup, interesting. But I'm not building a plane here just cabinets, vanties and that kind of thing, but I just don't like seeing that ~ and this script programming is addictive! You just keep adding on features and stuff you can do, I think I might have a problem. πŸ˜†

                      Thanks for the info

                      1 Reply Last reply
                      Reply Quote 0
                      • F
                        Frankn
                        last edited by

                        @tig said:

                        Here's Jim's clever solution made into a method...

                        def roundtofraction(num, frac)
                        >   num = num.to_f
                        >   frac = frac.to_f
                        >   return (num * frac).round / frac
                        > end
                        

                        Usage:

                        my_num = 0.17578125
                        my_frac = 16
                        my_num=roundtofraction(my_num, my_frac)

                        0.1875

                        Thanks yet again TIG! πŸ˜„

                        1 Reply Last reply
                        Reply Quote 0
                        • Chris FullmerC
                          Chris Fullmer
                          last edited by

                          Yeah TIG, thanks for wrapping it into its own method, now it feels at least slightly over-engineered πŸ˜„

                          Lately you've been tan, suspicious for the winter.
                          All my Plugins I've written

                          1 Reply Last reply
                          Reply Quote 0
                          • TIGT
                            TIG Moderator
                            last edited by

                            Anything to prolong the embarrassment πŸ˜‰

                            TIG

                            1 Reply Last reply
                            Reply Quote 0
                            • Chris FullmerC
                              Chris Fullmer
                              last edited by

                              @tig said:

                              Anything to prolong the embarrassment πŸ˜‰

                              πŸ‘ πŸ˜„

                              Lately you've been tan, suspicious for the winter.
                              All my Plugins I've written

                              1 Reply Last reply
                              Reply Quote 0
                              • Dan RathbunD
                                Dan Rathbun
                                last edited by

                                Just a note to remind all..

                                ... that now with Ruby in the 1.8.6 branch, we have both a ceil() and a floor() method defined for the Float class.

                                I'm not here much anymore.

                                1 Reply Last reply
                                Reply Quote 0

                                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                With your input, this post could be even better πŸ’—

                                Register Login
                                • 1 / 1
                                • First post
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement