MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Errors with decimal addition in Mathematica 5.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47427] Re: [mg47416] Errors with decimal addition in Mathematica 5.0
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Sun, 11 Apr 2004 04:44:04 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200404100601.CAA24300@smc.vnet.net>
  • Reply-to: murray at math.umass.edu
  • Sender: owner-wri-mathgroup at wolfram.com

You're confusing what you see with the numeric value actually found by 
Mathematica.

If you are using floating-point numbers, then by default, Mathematica 
displays only 6 digits (on most or all platforms).  To see more, use 
NumberForm.

In you case:

    13505.5 - 244.91
13260.6

    NumberForm[%, 10]    (* look at 10 correct digits, say *)
13260.59

The value calculated by Mathematica is correct, as you can demonstrate, 
for example, by something like the following:

   FractionalPart[13505.5 - 244.91]
0.59

In the last output you see both correct decimal places since there's no 
problem fitting all the digits into a default 6 displayed.


Peng Yu wrote:
> In[1]:= 13505.5 - 244.91
> Out[1]= 13260.6
> 
> However,13505.5 - 244.91 = 13260.59. "N" doesn't help, either.
> 
> In[25]:= N[13505.50 - 244.91]
> Out[25]= 13260.6
> 
> But the following command gives the correct answer.
> In[26]:= 505.50 - 244.91
> Out[26]= 260.59
> 
> How can I get the correct last digit? Thanks!
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Is there any productive way to use Mathematica + pdfLaTeX?
  • Next by Date: No more memory available... when using ExplicitEuler method for Diffusion equations in Mathematica NDSolve
  • Previous by thread: Errors with decimal addition in Mathematica 5.0
  • Next by thread: Re: Errors with decimal addition in Mathematica 5.0