Post Reply 
help with exact command. [Solved]
04-28-2016, 07:58 AM (This post was last modified: 04-28-2016 07:59 AM by retoa.)
Post: #9
RE: help with exact command. [Solved]
I wrote a little program to transform periodic numbers into fractions:


Code:

EXPORT periodo(n,la)
BEGIN
LOCAL a,b,e:=0,num,den;
 a:=n*10^la;
 b:=IP(a);
 WHILE FP(a)≠0 DO
  a:=10*a;
  e:=e+1;
 END;
 num:=a-b;
 den:=10^(e+la)-10^la;
 RETURN({numer(num/den),denom(num/den)});
END;
n is the number you want to transform with the periodical part written only once
la is the length of the antiperiod, 0 if no antiperiod
it returns a list with numerator and denominator of the fracion.

examples:

0.33333333
periodo(0.3,0) -> {1, 3}

2.353535353535
periodo(2.35,0) -> {233, 99}

3.456767676767 (the periodical part is 67, the antiperiod is 45, 2 digit length)
periodo(3.4567,2) -> {17111, 4950}

It should work independently of the number format settings.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
help with exact command. [Solved] - Spybot - 04-25-2016, 07:54 PM
RE: help with exact command. - Spybot - 04-25-2016, 08:33 PM
RE: help with exact command. - DrD - 04-25-2016, 09:27 PM
RE: help with exact command. - Spybot - 04-25-2016, 11:18 PM
RE: help with exact command. [Solved] - retoa - 04-28-2016 07:58 AM



User(s) browsing this thread: 1 Guest(s)