Message Boards Message Boards

GROUPS:

Simple alternative to N[x]

Posted 1 year ago
1438 Views
|
3 Replies
|
2 Total Likes
|

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
3 Replies
Posted 1 year 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

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

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

1`20 Pi
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