On 2007-12-17, Victor Fraenckel <victorf@[EMAIL PROTECTED]
> wrote:
> I would appreciate hearing from anyone who could point me to a place to
> grab a function the takes a floating point number and returns a string
> that represents that number as a integer (maybe) and a fraction like
> 3.25 = 3 1/4. Like this perhaps:
> var
> myfrac :string;
>
> myfrac = Num2Frac(num : single);
>
> My usage is for english units commonly found in carpentry like
> sixteenths, eighths, quarters and halves.
Better use SI :-)
Anyway, multiply the fractional part with a large power of two (e.g.
1024).
The resulting number is the upper part of your fraction, and 1024 below.
Then use the normal common denomitor way to simplify it to aa sane number.
- number: 3.25
- frac(3.25) = 0.25
- 0.25*1024=256
So 3 256/1024


|