Skip to content

RealDigits ​

The digits of a real number and the position of its decimal point, with the repeating block of a rational marked as a sublist.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageRealDigits✓
RealDigits(x)the exact digits of a rational (integers included), any repeating block nested
RealDigits(x, base)the same, in the given base
RealDigits(x, base, len)len digits — the exact expansion for a rational, or len digits of a numeric approximation (base 10 only) for anything else
Typed signatures
TypePackageApplies
(value, integer?, integer?) -> listnumeralsalways

Domain: Numeral systems

Details
  • The result is {{d₁, d₂, ...}, n}: the value is 0.d₁d₂d₃... × baseⁿ, so n is the count of digits before the point
  • A rational's expansion is EXACT: a terminating one stops, a repeating one nests its period as the list's last element — RealDigits(1/7) is {{{1,4,2,8,5,7}}, 0}
  • When the integer part is 0, leading fractional zeros are dropped from the digit list and folded into a more negative exponent instead of spelled out — RealDigits(1/8, 2) is {{1}, -2}, not {{0,0,1}, 0}
  • For anything without an exact rational value — Pi, a Sqrt, ExponentialE — len is required, and the digits are TRUNCATED, not rounded, from a numeric approximation computed a little beyond len digits
  • Sign is dropped, like every other digit head here

Examples

Basic #

the repeating block of 1/7=0.142857‾1/7 = 0.\overline{142857}

live ↗
InRealDigits(17)\mathrm{RealDigits}(\frac{1}{7})Out[[[1,4,2,8,5,7]],0]\bigl\lbrack\bigl\lbrack\bigl\lbrack1, 4, 2, 8, 5, 7\bigr\rbrack\bigr\rbrack, 0\bigr\rbrack

the first 10 digits of π\pi (truncated, not rounded)

live ↗
InRealDigits(π,10,10)\mathrm{RealDigits}(π, 10, 10)Out[[3,1,4,1,5,9,2,6,5,3],1]\bigl\lbrack\bigl\lbrack3, 1, 4, 1, 5, 9, 2, 6, 5, 3\bigr\rbrack, 1\bigr\rbrack

The first 25 digits of π\pi with exponent 1

live ↗
InRealDigits(π,10,25)\mathrm{RealDigits}(π, 10, 25)Out[[3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3],1]\bigl\lbrack\bigl\lbrack3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3\bigr\rbrack, 1\bigr\rbrack

A rational repeats: 19/7=2.714285‾19/7=2.\overline{714285}

live ↗
InRealDigits(197,10,25)\mathrm{RealDigits}(\frac{19}{7}, 10, 25)Out[[2,7,1,4,2,8,5,7,1,4,2,8,5,7,1,4,2,8,5,7,1,4,2,8,5],1]\bigl\lbrack\bigl\lbrack2, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5, 7, 1, 4, 2, 8, 5\bigr\rbrack, 1\bigr\rbrack
Scope #

19/7=2.714285‾19/7 = 2.\overline{714285}, one digit before the point

live ↗
InRealDigits(197)\mathrm{RealDigits}(\frac{19}{7})Out[[2,[7,1,4,2,8,5]],1]\bigl\lbrack\bigl\lbrack2, \bigl\lbrack7, 1, 4, 2, 8, 5\bigr\rbrack\bigr\rbrack, 1\bigr\rbrack

a terminating rational

live ↗
InRealDigits(54)\mathrm{RealDigits}(\frac{5}{4})Out[[1,2,5],1]\bigl\lbrack\bigl\lbrack1, 2, 5\bigr\rbrack, 1\bigr\rbrack

1/8=0.00121/8 = 0.001_2

live ↗
InRealDigits(18,2)\mathrm{RealDigits}(\frac{1}{8}, 2)Out[[1],−2]\bigl\lbrack\bigl\lbrack1\bigr\rbrack, -2\bigr\rbrack
live ↗
InRealDigits(2,10,5)\mathrm{RealDigits}(\sqrt{2}, 10, 5)Out[[1,4,1,4,2],1]\bigl\lbrack\bigl\lbrack1, 4, 1, 4, 2\bigr\rbrack, 1\bigr\rbrack
live ↗
InRealDigits(e,10,5)\mathrm{RealDigits}(e, 10, 5)Out[[2,7,1,8,2],1]\bigl\lbrack\bigl\lbrack2, 7, 1, 8, 2\bigr\rbrack, 1\bigr\rbrack

an integer: six digits before the point

live ↗
InRealDigits(123 456)\mathrm{RealDigits}(123\,456)Out[[1,2,3,4,5,6],6]\bigl\lbrack\bigl\lbrack1, 2, 3, 4, 5, 6\bigr\rbrack, 6\bigr\rbrack

A shorter digit count for π\pi

live ↗
InRealDigits(π,10,20)\mathrm{RealDigits}(π, 10, 20)Out[[3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4],1]\bigl\lbrack\bigl\lbrack3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4\bigr\rbrack, 1\bigr\rbrack
About
Examples11
Checked againstWolfram Language 11 agree
CrosswalkWolfram Language

See also: IntegerDigits, FromDigits