Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert string 1/4 or 1/2 to numeric
Message
From
19/01/2016 09:43:11
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
19/01/2016 08:49:13
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01629854
Message ID:
01629935
Views:
65
>>>How would you reverse that, Thomas?
>>>e.g. convert .25 to "1/4"
>>
>>Thats a pain, if it needs to work for any given number. In special if you need it reduced.
>>
>>I had this problems with distances, but they where all in fractions to the power of 2, so it was relative simple. I can borrow you this ancient code, if you like.
>
>Thank you for the offer, Lutz.
>
>My application carries decimal equivalents of sheet sizes for a printer and has to print them as fractions of inches.
>The numbers are all over the lot - 3/16", 5/8", 7/16", etc.
>(you folks don't have that problem, do you?)
>I solved it by dividing by 2 till I had something I could use.
>A built in function would have been handy.

I guess converting decimal fractions is one of the more tricky problems. Newer calculators can do it, sort of.
As long as there only powers of 2, like your problem, one can simply loop throug it.
Free fractions. Ooops. You will be soon into guessing. Any decimal number (assuming we do rational numbers) you can write down as a limited number of digits will be a fraction of a power of 2 times a power of 5. Only if the decimal fraction is long enough to see the period you can do anything else by guessing: 0.6666 might be 2/3 or it is 3333/5000. I have no idea how to express 0.6 period (how do you say this in english?) 6 to my comp ...

I do have such problems. I'm deal with pipes. Nominal diameters are real fun.
What I do is to have the proper fraction visible to the public and use the decimal fraction evaluated from this internaly.
So the user enters proper fractions (Then, by definition, its to handled as inch) or a decimal fraction (then it is in mm). I evaluate those value to my internal column in mm.
Big deal is a whole number as proper fraction - I have inherited a syntax n 0/0inch to destinguish from n[.0]mm

:)

Edit: Protip
The count of 2 you have to use is in the number of decimal places.
n places means divide by 2^n
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform