Replies: 1 comment
-
I wrote a quick and dirty Python CLI script to automatically do the trick above using qalc... #!/usr/bin/python3
from sys import argv
from subprocess import run
fpn = ''.join(argv[1:]).replace(' ', '').replace('…', '')
wn,_,dn = fpn.partition('.')
nrd,_,rd = dn.partition('_')
if not _:
print('Use an underscore to indicate start of repeating decimals')
exit()
sub = f'-{wn}{nrd}'if wn or nrd else ''
run(['qalc', f'({wn+nrd+rd}{sub})/{"9"*len(rd)+"0"*len(nrd)} to fraction']) Optionally make it executable: python3 repdeci-to-fraction -0.24_9 # ((−249) − (−24)) / 900 = −1/4
repdeci-to-fraction 33._3 # (333 − 33) / 9 = 33 + 1/3
repdeci-to-fraction 0.0_10 # (10 − 0) / 990 = 1/99 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I love qalc, it's fantastic. Rarely, but occasionally I would like to use rational numbers with repeating decimals obtained from other sources.
qalc can output fractions and can also output repeating decimals, which is great, but it doesn't appear to allow using repeating decimals as input.
Given rational numbers from an outside source, e.g.: 0.428571428571… , 2.6363… , 4.567878…, 5.8144144…, 0.0476190476190…
How could we input rational numbers with repeating decimals precisely in qalc (or easily determine the fraction)?
I realize we can use qalc with the standard trick: shifting repeating decimals to the left past the decimal point, less the non-repeating part, then dividing by the number of shifts with 9s for repeating and 0s for non-repeating:
So that works, but would there be an easier way using qalc?
Thank you.
p.s. It's fun that qalc supports unicode fractions input, e.g.: 1⅐, ⅔ :)
Beta Was this translation helpful? Give feedback.
All reactions