HP Forums
How do you enter a repeating decimal - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How do you enter a repeating decimal (/thread-16830.html)



How do you enter a repeating decimal - MullenJohn - 04-28-2021 02:43 PM

Help,

Using the HP Prime how does one enter a repeating decimal such as 2.(777), i.e. 2.777...777...?

Thanks - Cheers!


RE: How do you enter a repeating decimal - cdmackay - 04-28-2021 03:28 PM

(04-28-2021 02:43 PM)MullenJohn Wrote:  Help,

Using the HP Prime how does one enter a repeating decimal such as 2.(777), i.e. 2.777...777...?

Thanks - Cheers!

2 + 7/9 ? Smile

seriously, I don't know, but would be interested to hear.


RE: How do you enter a repeating decimal - Joe Horn - 04-28-2021 05:44 PM

(04-28-2021 03:28 PM)cdmackay Wrote:  
(04-28-2021 02:43 PM)MullenJohn Wrote:  Help,

Using the HP Prime how does one enter a repeating decimal such as 2.(777), i.e. 2.777...777...?

Thanks - Cheers!

2 + 7/9 ? Smile

seriously, I don't know, but would be interested to hear.

That's the best way. Just use as many 9's as there are repeating digits:
71.232323232323... = 71+23/99 (two 9's because there are two repeating digits)
71.234234234234... = 71+234/999 (three 9's because there are three repeating digits)

If the repeating digits do not begin immediately after the decimal point, then ALSO insert as many zeros after the 9's as there are non-repeating digits after the decimal point:
71.2344444444444... = 71.23 + 4/900
(One 9 because one digit is repeating; two 0's because two digits after the decimal point don't repeat)
71.2345656565656... = 71.234 + 56/99000
(two 9's because two digits repeat; three 0's because three digits after the decimal point don't repeat)

This is especially useful in CAS where the above yield exact results. In Home, it's often more efficient to simply key in the decimal approximation, since Home view is intended for approximate math anyway.


RE: How do you enter a repeating decimal - jonmoore - 04-29-2021 11:07 AM

(04-28-2021 05:44 PM)Joe Horn Wrote:  This is especially useful in CAS where the above yield exact results. In Home, it's often more efficient to simply key in the decimal approximation, since Home view is intended for approximate math anyway.

Great tips Joe.

But this reminds me of a bugbear with the prime. The only way to change an improper fraction result to a mixed fraction in the CAS view is to use the propFrac function. The a b/c key only works with fractions in the Home view, where more often than not, you're working with approximate decimal values.

I'm not sure if my memory is playing tricks on me, but I could swear it wasn't always this way.


RE: How do you enter a repeating decimal - Albert Chan - 04-29-2021 01:07 PM

I had coded repeating decimal conversion in Python, long time ago.
Code:
def dratio(s):
    'Return decimals (with no exponent) as ratio'
    s = s.rstrip(') \t')
    i = s.find('.')
    if i < 0: return int(s), 1  # assume integer, if no decimal point
    j = s.find('(', i+1)        # repeating decimal start
    if j < 0: return int(s[:i]+s[i+1:]), 10 ** (len(s)-i-1)
    r = 10 ** (len(s)-j-1)      # handle repeating decimals
    k = int( s[:i] + s[i+1:j] + s[j+1:] )
    return k - k//r - (k<0), (r-1) * 10 ** (j-i-1)

>>> map(dratio, ['2.(777)', '71.23(4)', '71.234(56)'])
[(2775, 999), (64111, 900), (7052222, 99000)]
>>> [n/d for (n,d) in _]
[2.7777777777777777, 71.234444444444449, 71.23456565656565]


Code get the correct ratio, but not fully reduced. Fix is easy, if needed.

>>> import fractions
>>> dtoF = lambda s: fractions.Fraction(*dratio(s))
>>> map(dtoF, ['2.(777)', '71.23(4)', '71.234(56'])
[Fraction(25, 9), Fraction(64111, 900), Fraction(3526111, 49500)]