Today, for the first time since I started programming - about 30 years, a client asked for a percentage to be shown as a fraction.
This is for 'strike rates' for their estimators - if they achieve a 20% success rate, they want to see 1/5 (one in five)
I can't find any code for this - so I am using this:
Does anyone have any other ideas?
Regards
Griff
Keep [Smile]ing
This is for 'strike rates' for their estimators - if they achieve a 20% success rate, they want to see 1/5 (one in five)
I can't find any code for this - so I am using this:
Code:
FUNCTION PC2FRACT
PARAMETER m.PERVALUE
PRIVATE m.PERVALUE,m.MYDIVIDER,m.FLAG,I,m.STRING
m.MYDIVIDER = 100
m.STRING = ""
m.PERVALUE = (ROUND(m.PERVALUE*4,0) /4 )
m.FLAG = .F.
I = m.MYDIVIDER
** run down from 100 to highest common divider preserving index
DO WHILE m.FLAG = .F. .AND. I >= 1
IF INT(m.MYDIVIDER/I) = m.MYDIVIDER /I .AND. INT(m.PERVALUE /I) = m.PERVALUE /I
** bingo
m.FLAG = .T.
ELSE
** come down in units of 25 initially
IF I > 25
I = I - 25
ELSE
** then 5s
IF I > 5
I = I - 5
ELSE
** and then 1s
I = I -1
ENDIF
ENDIF
ENDIF
ENDDO
IF m.FLAG
** if you got a sensible match, use it
m.STRING = STR(m.PERVALUE / I,4,0) +" / "+ STR(m.MYDIVIDER / I,4,0)
ELSE
** other express as over 100
m.STRING = STR(m.PERVALUE ,4,0) + " / 100"
ENDIF
RETURN(m.STRING)
Does anyone have any other ideas?
Regards
Griff
Keep [Smile]ing
There are 10 kinds of people in the world, those who understand binary and those who don't.
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.