sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Converting text to unit length (string.to_l)

    Scheduled Pinned Locked Moved Developers' Forum
    2 Posts 2 Posters 137 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.
    • R Offline
      RickW
      last edited by

      Originally posted on the Smustard forum:

      Be careful when using string.to_l to convert text to unit length. Windows users in countries that use "," for decimal separation will likely have regional settings active for their OS, and Ruby is dependent on those regional settings. For the US, "23.563m".to_l will work fine, but in those locales, it will fail. Conversely, "23,563m".to_l will work on their machines, but will fail where "." is used for decimal separation.

      A simple begin/rescue/end can set a class or instance variable for handling the proper notation convention. I may try to code this into a separate class.

      RickW
      [www.smustard.com](http://www.smustard.com)

      1 Reply Last reply Reply Quote 0
      • J Offline
        jhoutman
        last edited by

        Yes, I was worried about this problem. In my woodwrk.rb I use a simple math evaluator as an alternate to simply a math expression. I parse the string and where there are legitimate length fields I insert the following: s.to_l.to_f.to_s.
        If fear this won't work in European countries although I do know at least one guy using my Ruby.

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

        Advertisement