Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Decimals to Fractions
Message
 
 
À
01/07/1999 14:21:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00236602
Message ID:
00236733
Vues:
13
Brian,

Here's a function accurate to 1/16 inches.
* InchToString.prg 08-Oct-98

* Convert decimal inches to string for display

lparameter lnValue

local lnInches, lnFrac, lcInches, lcFrac, lnValue

lnInches = int( lnValue )
lnFrac = round( ( lnValue - lnInches ) * 16, 0 )
lcInches = iif( lnInches > 0, alltrim( str( lnInches ) ), "" )
do case
   case ( lnFrac = 0 )
      lcFrac = ""
   case ( lnFrac % 8 = 0 )
      lcFrac = str( lnFrac / 8, 1 ) + "/2"
   case ( lnFrac % 4 = 0 )
      lcFrac = str( lnFrac / 4, 1 ) + "/4"
   case ( lnFrac % 2 = 0 )
      lcFrac = str( lnFrac / 2, 1 ) + "/8"
   otherwise
      lcFrac = alltrim( str( lnFrac ) ) + "/16"
endcase

return( alltrim( lcInches + " " + lcFrac ) )
>Has anyone ever seen a routine that will take a decimal number, and output a string that is formatted as a fraction. For instance, send in .25, and it will return "1/4". Any help would be great.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform