Simple alternative to N[x]

A fast way to get an exact fraction into its real-number equivalent is to multiply by 1.0 (or just 1.)

Example:

In[1]:= x = 355/113

Out[1]= 355/113

In[2]:= 1.0 x

Out[2]= 3.14159

In[3]:= N[x]

Out[3]= 3.14159
1 Like

I’ll add the note that this is exactly what Maeder recommended in the first edition of Programming in Mathematica, back when Mathematica did not have the ability to propagate inexact numbers throughout a computation (pre-version 2, IIRC).

@S.M. Blinder You can also add a decimal point to the numerator or denominator and achieve the same thing. The Postfix //N works as well.

1 Like

And if you want it to a certain number of digits, you can use something like

1`20 Pi