Message Boards Message Boards

Simple alternative to N[x]

GROUPS:

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
POSTED BY: S M Blinder
Answer
2 months ago

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).

POSTED BY: J. M.
Answer
2 months ago

@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.

POSTED BY: Ed Forrester
Answer
2 months ago

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

1`20 Pi
POSTED BY: Szabolcs Horvát
Answer
2 months ago

Group Abstract Group Abstract