3
$\begingroup$

I have N[Sqrt[2], 8] which outputs 0.4142136

How do I get the 4142136 part out of it? I tried RealDigits[N[Sqrt[2], 8] - Floor@Sqrt[2]][[1]] but because in the solution above the last digit was rounded up (0.41421356), it doesn't come out the same : {4, 1, 4, 2, 1, 3, 5}

$\endgroup$
2
  • 1
    $\begingroup$ I would be helpful if you could add what you want to do with the result. Do you need an integer like 4142136 or a string "4142136" or is a list like your last output OK? $\endgroup$ Commented Feb 21, 2015 at 3:30
  • $\begingroup$ halirutan, I want a list of digits or a number. In the end I need to add the digits after the decimal. $\endgroup$ Commented Feb 21, 2015 at 3:33

2 Answers 2

5
$\begingroup$
FractionalPart@N[Sqrt[2], 7] 10^7 // Round (* 4142136*) 
$\endgroup$
1
  • $\begingroup$ That works, thanks :] I thought about doing it that way but for some reason decided that it wouldn't work for a large number of sig figs >.> ... but it totally does ... <.< $\endgroup$ Commented Feb 21, 2015 at 3:38
4
$\begingroup$

A way to work with RealDigits, if desired:

Drop @@ RealDigits[Round[Sqrt[2], 1*^-7]] // FromDigits 
4142136 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.