Wolfram Research

Function Repository Resource:

RecurringDecimalForm (1.0.0) current version: 1.0.1 »

Source Notebook

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

Contributed by: Jon McLoone  |  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

RecurringDecimalForm takes the following options:
"MinRepeats"3number of times digits must repeat before they are assumed to be recurring
"RoundingDigits"1 number 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) 

All rational numbers result in 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 (3) 

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

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

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

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

The option "MinRepeats" controls this sensitivity:

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

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]=

Version History

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

Source Metadata

Related Resources

License Information