home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 2,576 of 2,978   
   Marco van de Voort to Victor Fraenckel   
   Re: Looking for function   
   17 Dec 07 08:47:23   
   
   From: marcov@stack.nl   
      
   On 2007-12-17, Victor Fraenckel  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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca