Message Boards Message Boards

1
|
8921 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

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
POSTED BY: S M Blinder
3 Replies

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

1`20 Pi
POSTED BY: Szabolcs Horvát

@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
Posted 7 years 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.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract