1 | initial version |
Sage integers have a digits
method which returns the list of digits, with units digit last, preceded by 10's digit, etc.:
sage: a = 31415
sage: a.digits()
[5, 1, 4, 1, 3]
So you could do:
sage: pie = pi.n(digits = 10)
sage: pied = (pie * 10**10).trunc()
sage: pied
31415926535
sage: pi_digits = pied.digits()
sage: pi_digits
[5, 3, 5, 6, 2, 9, 5, 1, 4, 1, 3]
sage: sum(10**index * digit for (index, digit) in enumerate(pi_digits))
31415926535
2 | No.2 Revision |
Sage integers have a digits
method which returns the list of digits, with units digit last, preceded by 10's digit, etc.:
sage: a = 31415
sage: a.digits()
[5, 1, 4, 1, 3]
So you could do:
sage: pie = pi.n(digits = 10)
sage: pied = (pie * 10**10).trunc()
10**10).trunc() # get an integer
sage: pied
31415926535
sage: pi_digits = pied.digits()
sage: pi_digits
[5, 3, 5, 6, 2, 9, 5, 1, 4, 1, 3]
sage: sum(10**index * digit for (index, digit) in enumerate(pi_digits))
31415926535