Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Is it possible to use relations in a repeat relation to covert decimal #s to fractions?
I was having issues with some ITOS formulas I found online but I developed some if statements that work well. (sample below) They work well at the part level but I am having issues adapting for the repeat region.
WHOLE=FLOOR(ASM_MBR_FLAT_PATT_L) |
DECIMAL=ASM_MBR_FLAT_PATT_L-WHOLE |
IF (DECIMAL<.03125) |
FRACTION="" |
ELSE |
IF DEAD(DECIMAL,0.03125,0.09374)==0 |
FRACTION="1/16" |
ELSE |
IF DEAD(DECIMAL,0.09375,0.15624)==0 |
FRACTION="1/8" |
ELSE |
IF DEAD(DECIMAL,0.15625,0.21874)==0 |
FRACTION="3/16" |
ELSE |
IF DEAD(DECIMAL,0.21875,0.28124)==0 |
FRACTION="1/4" |
ELSE |
As you've found, relations are pretty terrible for doing things like calculating the fractional equivalent of a decimal number, because they lack basic looping capabilities, You're therefore forced to a rather unweildy clump of nested IF-ENDIF statements. It works, but is really not a nice construct.
Anyway, I don't know what kind of relations examples you've found but here's a chunk from one of my generic bolt models that is trying to calculate the "multiple of 2" fraction (2, 4, 8, 16, 32) that a given decimal number is closest to. Hopefully that's the kind of fraction you are after, and not things like 11/13 and the like
In this snippet, diaNom is the number being looked at, and txtDiaNom is the resultant string containing the fraction.
txtDiaNom = ITOS ( floor ( diaNom * 32 ) ) + "/32"
IF MOD ( floor ( diaNom * 32 ), 2 ) < 1
txtDiaNom = ITOS ( floor ( diaNom * 16 ) ) + "/16"
IF MOD ( floor ( diaNom * 16 ), 2 ) < 1
txtDiaNom = ITOS ( floor ( diaNom * 8 ) ) + "/8"
IF MOD ( floor ( diaNom * 8 ), 2 ) < 1
txtDiaNom = ITOS ( floor ( diaNom * 4 ) ) + "/4"
IF MOD ( floor ( diaNom * 4 ), 2 ) < 1
txtDiaNom = ITOS ( floor ( diaNom * 2 ) ) + "/2"
ENDIF
ENDIF
ENDIF
ENDIF
Hopefully all the functions (MOD, floor, ITOS) are available in repeat region calculations.
Actually more interested in how to place relations in the repeat region and have the work than the formulas themselves but thank you for the information.