Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Decimals to Fractions
Message
 
 
To
01/07/1999 14:21:45
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00236602
Message ID:
00236733
Views:
12
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
Previous
Reply
Map
View

Click here to load this message in the networking platform