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

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}

• First[RealDigits[x]]? Commented Jan 22, 2015 at 21:19
• @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! Commented Jan 22, 2015 at 21:29
• @MichaelE2 using your example I am not getting the output that I am looking for :s, thank you for trying! Commented Jan 22, 2015 at 21:29

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.16864323410;

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! Commented Jan 22, 2015 at 21:48
• @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. Commented Jan 22, 2015 at 21:53
• I will keep that in mind! My apologies, reading through rules of this forum! Commented Jan 22, 2015 at 22:25
• @user1989, No apology necessary! It's not a rule, just a good tactic to get the best out of the site :-) Commented Jan 22, 2015 at 22:40