Not the most amazing thing on here but it's a pretty tidy program.
11 lines:
sync on:iter=0:n#=0.5:do :cls:print "This program converts decimal numbers to fractions and back again.":print "Enter a decimal number:>":sync
for iter = 0 to 4:f$ = dec2frac$(n#):print n#; " = "; f$:print "converted back to a decimal number:"; frac2dec(f$):sync:input n#:next iter :loop
function dec2frac$(dec#)
for b = 1 to 1000 :a# = b*dec#:a = round2int(a#):if abs(a# - a) < 0.0001:exit:endif:next b
if b > 1000:exitfunction "conversion failed!":else:frac$ = str$(a)+"/"+str$(b):endif
endfunction frac$
function round2int(n#)
endfunction int(n#+n#) - int(n#)
function frac2dec(a$)
num# = val(a$):a$ = right$(a$, len(a$)-len(str$(num#))-1):den# = val(a$)
endfunction num#/den#
Uncompressed
rem Fraction to Decimal converter by OBese87
sync on
sync
iter=0
n#=0.5
rem ==========================================================
rem = Main
rem ==========================================================
do
cls
print "This program converts decimal numbers to fractions and back again."
print "Enter a decimal number:>"
sync
for iter = 0 to 4
f$ = dec2frac$(n#)
print n#; " = "; f$
print "converted back to a decimal number:"; frac2dec(f$)
sync
input n#
next iter
loop
rem ==========================================================
rem = Functions
rem ==========================================================
function dec2frac$(dec#)
for b = 1 to 1000
a# = b*dec#
a = round2int(a#)
if abs(a# - a) < 0.0001 then exit
next b
if b > 1000
exitfunction "conversion failed!"
else
frac$ = str$(a)+"/"+str$(b)
endif
endfunction frac$
`//
function round2int(n#)
n = int(n#+n#) - int(n#)
endfunction n
`//
function frac2dec(a$)
num# = val(a$)
a$ = right$(a$, len(a$)-len(str$(num#))-1)
den# = val(a$)
endfunction num#/den#
WARNING: The above comment may contain sarcasm.