Fractions and units display
-
I have the K2WS_Tools out for beta testing and a problem has shown up with fractions with unit display checked. I pass the input to Arithmetic parsing so fractions and equations are accepted. However with an input of 1/4" the units display the input is not processed into an SU length and the program bombs. I am thinking about parsing the input to remove the trailing " as I could in basic but so far I have not found enough the help file to tell me how to do this. I could use your help.
Or if there is a better way of handling this problem I am also open to suggestions.
Thanks
Keith -
Should you just split the string '1/4"' at the / then take then add a " to the first part then make both into lengths then do the division ?
input='1/4"'
1/4"
fract=input.split("/")
["1", "4""]
fact[0]=fract[0]+'"'
"1""
fract
["1"", "4""]
ans=fract[0].to_l / fract[1].to_l
0.25OR perhaps even easier you could strip off the trailing " thus
input.gsub!(/"$/,'')
1/4
fract=input.split("/")
["1", "4"]
ans=fract[0].to_f / fract[1].to_f
0.25 -
Is there a model variable that would tell me what the units setting is? It might help the problem if I could change the units while the program runs and then change it back before the program exits. I did find a way to strip the inch unit sign
@hasInch = @fpt.to_s =~ /\"/ ; if @hasInch then @fpt=@fpt[0,@hasInch] end
however this was not a complete solution as calculations still stopped the program.
@xcl[0]=x1+(@hpt-((@fpt)/2))
These equations don't work when the @fpt variable is a fraction. And I also found out that other areas of my program where I am working on geom a float number does not seem to work. There are obviously many things I don't understand about length variables. Any thoughts or suggestions will be appreciated.
Keith
-
Not sure what the problem is? What are you trying to do?
Advertisement