Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Is there a preferred way of converting an Integer to a Real?

What I'm using at the moment is x + 0.0.

share|improve this question
11  
N is what I use. –  Michael E2 Oct 15 '13 at 19:20
2  
@MichaelE2 your chance to post a canonical answer using one character ;-) –  Yves Klett Oct 16 '13 at 5:24
    
Although the answer is trivial, there is no one-hit wonder on google or in the documentation. The first immediately useful hit is reference.wolfram.com/legacy/v2/contents/3.1.2.pdf, which is already running under "legacy", so I would vote against closure as long as @MichaelE2 posts his comment as answer. –  Yves Klett Oct 16 '13 at 7:57
    
@yvesklett I was about to vote to close, but you're right, unfortunately. I have been trying to find an answer to this question as if I were a newbie. There just doesnt seem to be an easy and intuitive way a new user could arrive at the answer, at least not from the online documentation. –  Sjoerd C. de Vries Oct 16 '13 at 9:33
    
@SjoerdC.deVries my first reflex was also to close (as in quite a few cases these last days). It may be a duplicate, but in fact this title question and the straightforward answer may be even more useful for newbies. –  Yves Klett Oct 16 '13 at 11:29

3 Answers 3

up vote 7 down vote accepted

N


A one-character answer is disallowed by SE, so I will expand. N is mostly what I use. If I have an expression like $2 x + 3$, I sometimes write it 2. x + 3. in Mathematica; then if x is numeric, whether it happens to be an Integer or not, the expression will always be Real or Complex.

share|improve this answer
    
Indeed, the last part of the statement is always true, my bad. Well... actually, if x is something completely different..... :) –  István Zachar Oct 16 '13 at 11:17
Head /@ {23, 23*1, 23/1, 23 + 0, 23., 23*1., 23/1., 23 + 0.}

{Integer, Integer, Integer, Integer, Real, Real, Real, Real}

share|improve this answer

This also

{Head[1], Head[1 // N]}

{Integer, Real}

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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