16
$\begingroup$

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.

$\endgroup$
1
  • 11
    $\begingroup$ It's probably easiest to just add it as a fractional term if you need arbitrary precision 12/100+(34/99)/100. $\endgroup$
    – eyorble
    Feb 25, 2021 at 1:16

3 Answers 3

30
$\begingroup$

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
$\endgroup$
1
  • 1
    $\begingroup$ Thank you very much. $\endgroup$ Feb 25, 2021 at 2:04
16
$\begingroup$

Use the ResourceFunction RepeatingDecimalToRational:

ResourceFunction["RepeatingDecimalToRational"][0.3, 1]

(* 1/3 *)
$\endgroup$
0
$\begingroup$

I'm not sure if WolframAlpha notation is identical with Mathematica, although in the question you look like you used the 0.12343434... (3 dots), but in WolframAlpha (this is how I got to this question), you can use:

0.123434..

for 0.12(34)

WolframAlpha and Mathematica should be the same software under the covers having Steven Wolfram as creator. If not, I will let it as reference for those looking for WolframAlpha equivalent.

$\endgroup$
4
  • 2
    $\begingroup$ This may be not a repeating decimal. You do not know what numbers come after. $\endgroup$ Aug 11, 2023 at 19:24
  • 2
    $\begingroup$ For what it's worth, 0.123434.. does NOT work in Mathematica to represent a number with repeating digits. The expression 0.123434 .. just the same as Repeated[0.123434] which is a pattern. I.e. MatchQ[{0.123434, 0.123434, 0.123434}, {Repeated[0.123434]}] would return True. $\endgroup$
    – lericr
    Aug 11, 2023 at 20:07
  • $\begingroup$ Thank you @lericr. I understand and agree with you (+1). Do you think it worth leaving this answer only for context and equivalence for WolframAlpha ? Thank you @Валерий Заподовников (+1)! $\endgroup$
    – azbarcea
    Aug 11, 2023 at 20:41
  • 1
    $\begingroup$ My recommendation would be to delete it, but it's a judgment call and I'm fine either way. $\endgroup$
    – lericr
    Aug 11, 2023 at 21:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.