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$
  • 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$ – halirutan Feb 21 '15 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$ – Raksha Feb 21 '15 at 3:33
5
$\begingroup$
FractionalPart@N[Sqrt[2], 7] 10^7 // Round
(* 4142136*)
$\endgroup$
  • $\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$ – Raksha Feb 21 '15 at 3:38
4
$\begingroup$

A way to work with RealDigits, if desired:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.