Function Repository Resource:

RecurringDecimalForm

Source Notebook

Display a number in decimal form so that recurring digit sequences are highlighted and displayed only once

Contributed by: Jon McLoone

ResourceFunction["RecurringDecimalForm"][val]

displays numeric value val such that recurring digits are highlighted and displayed only once.

ResourceFunction["RecurringDecimalForm"][val,b]

displays numeric value val such that digits recurring in base b are highlighted and displayed only once.

Details and Options

ResourceFunction["RecurringDecimalForm"] takes the following options:
"MinRepeats"3number of times digits must repeat before they are assumed to be recurring
"RoundingDigits"1number assumed to be affected by rounding and, as such, ignored
"Notation""Vinculum"display notation to be used for recurring digits; choices are "Vinculum", "Dots", "Parenthesis" or "Arc"

Examples

Basic Examples (2) 

Some rational numbers have recurring decimal digits:

In[1]:=
N[1/11, 31]
Out[1]=

RecurringDecimalForm displays this in a more compact notation:

In[2]:=
ResourceFunction["RecurringDecimalForm"][1/11]
Out[2]=

Scope (5) 

RecurringDecimalForm accepts any input that is numeric:

In[3]:=
ResourceFunction["RecurringDecimalForm"][3.431212121212121212]
Out[3]=

RecurringDecimalForm ignores repeating zeros:

In[4]:=
N[1/8]
Out[4]=
In[5]:=
ResourceFunction["RecurringDecimalForm"][1/8]
Out[5]=

For numeric quantities, a repeating sequence in the final digits (excluding the last digit, which is subject to rounding) is assumed to be recurring:

In[6]:=
ResourceFunction["RecurringDecimalForm"][1.23456565656565657]
Out[6]=

For exact numeric quantities that are not explicitly Rational, RecurringDecimalForm searches the first $MaxExtraPrecision digits:

In[7]:=
ResourceFunction["RecurringDecimalForm"][Sin[1]]
Out[7]=

Recurring digits can be found in other number bases:

In[8]:=
ResourceFunction["RecurringDecimalForm"][0.2`30, 2]
Out[8]=

Options (6) 

MinRepeats (2) 

Digit sequences that repeat at least three times are assumed to be recurring:

In[9]:=
ResourceFunction["RecurringDecimalForm"][1.31234567123456712]
Out[9]=

The option "MinRepeats" controls this sensitivity:

In[10]:=
ResourceFunction["RecurringDecimalForm"][1.31234567123456712, "MinRepeats" -> 2]
Out[10]=

Notation (1) 

There are several notations for the display of recurring digits used in different parts of the world:

In[11]:=
Table[ResourceFunction["RecurringDecimalForm"][1/111, "Notation" -> n], {n, {"Vinculum", "Dots", "Parenthesis", "Arc"}}]
Out[11]=

RoundingDigits (3) 

By default, the final digit is assumed to be subject to rounding and is ignored:

In[12]:=
ResourceFunction["RecurringDecimalForm"][0.6666666666666666666667]
Out[12]=

In some circumstances, more digits are affected by rounding:

In[13]:=
RealDigits[0.2, 2]
Out[13]=
In[14]:=
ResourceFunction["RecurringDecimalForm"][0.2, 2]
Out[14]=

You can ignore more digits with "RoundingDigits":

In[15]:=
ResourceFunction["RecurringDecimalForm"][0.2, 2, "RoundingDigits" -> 2]
Out[15]=

Possible Issues (4) 

By default, the final digit is assumed to be subject to rounding and is ignored:

In[16]:=
ResourceFunction["RecurringDecimalForm"][0.6666666666666666666667]
Out[16]=
In[17]:=
Rationalize[
 ToExpression[StringJoin["0.", StringJoin[Table["0999", {10}]]]]]
Out[17]=

In some circumstances, more digits are affected by rounding:

In[18]:=
111/1111`30
Out[18]=

In these circumstances, RecurringDecimalForm will not recognize the repeat:

In[19]:=
ResourceFunction["RecurringDecimalForm"][111/1111`30]
Out[19]=

You can ignore more digits with "RoundingDigits":

In[20]:=
ResourceFunction["RecurringDecimalForm"][111/1111`30, "RoundingDigits" -> 3]
Out[20]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 08 April 2022
  • 1.0.0 – 06 December 2019

Related Resources

License Information