Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert decimal to fraction
Message
 
À
10/02/2003 19:14:34
Fabian Belo
Independent Developer
Argentine
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00751688
Message ID:
00751852
Vues:
28
It works great... thanks a lot!

This is what I did to test it - I only needed 1,2,4,8,16,32,64 (for cut measurements of materials).
CREATE CURSOR _decimals (cfracstart c(20),cdecimal c(20),cfracres C(20))
SELECT _decimals
j=1
DO WHILE j <= 64
	FOR i = 1 to j
		lnfraction = i/j
		lcfraction = _DecToFraction(lnfraction)
		? ALLTRIM(STR(i))+ "/"+ALLTRIM(STR(j)) + " --> " + lcfraction
		m.cfracstart 	= ALLTRIM(STR(i))+ "/"+ALLTRIM(STR(j))
		m.cdecimal 	= ALLTRIM(STR(lnfraction,10,5))
		m.cfracres 	= lcfraction
		INSERT INTO _decimals FROM MEMVAR 
		
	NEXT i
	j=j*2
ENDDO 
BTW, keep your eye out for next month's UT Magazine... you just might be in it!

>I've made this function few weeks ago:
>
>
>FUNCTION _DecToFraction(nDec1)
>*-----------------------------------
>* Transforma de Decimal a Fraccion
>* Uso:  _DecToFraction(nDec1)
>* Devuelve:  Caracter
>*-----------------------------------
>	LOCAL cRes, nCon
>	nCon = 0
>	cRes = "No Fraction"
>	DO WHILE nCon<1000000
>		nCon = nCon+1
>		DO CASE
>			CASE MOD(nCon,nDec1)=0
>				cRes=ALLTRIM(STR(nCon))+"/"+ALLTRIM(STR(nCon/nDec1))
>				EXIT
>		ENDCASE
>	ENDDO
>	RETURN cRes
>ENDFUNC
>
>
>>I need to convert a decimal to a fraction... anyone have/know of a function for this?
>>
>>
>>.5 --> 1/2
>>
>>.1875 --> 3/16
>>
>>TIA
Wayne Myers, MCSD
Senior Consultant
Forte' Incorporated
"The only things you can take to heaven are those which you give away" Author Unknown
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform