How to enter a repeating decimal in Mathematica

11

1

I don't understand how to manipulate numbers with repeating decimal in Wolfram Mathematica language.

For example 0.3... does not work as input and I don't see how to add a vinculum to indicate the repeating part either. There's no manual or something on the issue on the net. Something strange and unusable 0.12(34)^_ (repeating decimal) is given by Wolfram Alpha.

Simpleton Jack

Posted 2021-02-25T01:14:22.723

Reputation: 2 565

7It's probably easiest to just add it as a fractional term if you need arbitrary precision 12/100+(34/99)/100. – eyorble – 2021-02-25T01:16:30.033

Answers

17

Indeed, there is no direct method to input a repeating decimal. The closest you can get is to input the repeating digits into FromDigits[]:

$$0.\overline{142857}$$

FromDigits[{{{1, 4, 2, 8, 5, 7}}, 0}]
   1/7

$$0.\overline{3}$$

FromDigits[{{{3}}, 0}]
   1/3

$$0.1\overline{6}$$

FromDigits[{{1, {6}}, 0}]
   1/6

Of course, this also applies for e.g. repeating binary representations:

$${0.000\overline{1100}}_2$$

FromDigits[{{0, 0, 0, {1, 1, 0, 0}}, 0}, 2]
   1/10

J. M.'s ennui

Posted 2021-02-25T01:14:22.723

Reputation: 115 520

1Thank you very much. – Simpleton Jack – 2021-02-25T02:04:13.093

11

Use the Resource Function

ResourceFunction["RepeatingDecimalToRational"][0.3, 1]

(* 1/3 *)

Bob Hanlon

Posted 2021-02-25T01:14:22.723

Reputation: 95 281