## How-to convert real number into List of its digits?

2

How could I convert a real number into a List of its digits in Mathematica?

Example:

8.168643234

Desired output:

{8,1,6,8,6,4,3,2,3,4}

3First[RealDigits[x]]? – Michael E2 – 2015-01-22T21:19:12.580

@bbgodfrey thank you! I only just started working with Mathematica and I find it all brand new. I am a software engineer. I am looking to learn more about wolfram language! – user1989 – 2015-01-22T21:29:04.620

@MichaelE2 using your example I am not getting the output that I am looking for :s, thank you for trying! – user1989 – 2015-01-22T21:29:48.910

5

When you enter a number with a decimal point like:

x = 8.168643234;

you are telling Mathematica that this is a machine precision number. You can see this with:

Precision[x]
(* MachinePrecision *)

This means that the internal representation of the number is not exactly what you entered, but instead is the nearest machine real. RealDigits shows you the digits in the actual value of x:

First[RealDigits[x]]
(* {8, 1, 6, 8, 6, 4, 3, 2, 3, 3, 9, 9, 9, 9, 9, 9} *)

If you want to get the exact output in the question, you will need to either specify the precision of the number:

x = 8.168643234`10;

First[RealDigits[x]]
(* {8, 1, 6, 8, 6, 4, 3, 2, 3, 4} *)

or enter it as an exact (infinite precision) number:

x = 8168643234*10^-9;

First[RealDigits[x]]
(* {8, 1, 6, 8, 6, 4, 3, 2, 3, 4} *)

Thank you very much for your time answering my question. I appreciate your effort! – user1989 – 2015-01-22T21:48:56.000

@user1989, no problem. By the way it is usual here to wait a while before accepting an answer, so as not to discourage others from posting other, potentially better, answers. 24 hours is good as it gives the whole globe a chance to contribute. – Simon Woods – 2015-01-22T21:53:39.953

I will keep that in mind! My apologies, reading through rules of this forum! – user1989 – 2015-01-22T22:25:53.777

1@user1989, No apology necessary! It's not a rule, just a good tactic to get the best out of the site :-) – Simon Woods – 2015-01-22T22:40:34.540