Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Precision
Replies: 4   Last Post: Jan 7, 2013 11:05 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Murray Eisenberg

Posts: 2,105
Registered: 12/6/04
Re: Precision
Posted: Jan 7, 2013 11:05 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Of course in the case of dollars and cents, one should not ordinarily need to worry about loss of precision -- unless one is dealing with "exact" quantities on the order of the U.S. National Debt, which is roughly 2 * 10^13 and hence, including cents, would use 16 digits.

On Jan 7, 2013, at 12:38 AM, Andrzej Kozlowski <akozlowski@gmail.com> wrote:

> On 5 Jan 2013, at 08:19, Rob Ryan <tio540s1@gmail.com> wrote:

>> My frustration is growing. I simply want to add (for example):
>> 103971.66+52282.64+2998.27. These are dollars and cents and I'd like to keep the cents. But when I input that line, I get 159923. When I input: N[(103971.66+52282.64+2998.27),20] I STILL get 159923. What do I do to get 159952.57? I've used "SetPrecision", etc. with still no result.
>> I note that when I type 103971.66 and hit shift-return, the output is 103972. If I then type "InputForm[%]" I get 103971.66.
>> There simply has to be an easy way to add these numbers - any calculator watch can do it!

> In this case you can simply use NumberForm:
> NumberForm[103971.66 + 52282.64 + 2998.27, 8]
> 159252.57
> However, this approach will not always work (to understand why you have to first understand that Mathematica's approximate reals are not what you probably think they are)
> A much more reliable way is to do such computations using exact numbers. This will never give you a wrong answer:
> QuotientRemainder[10397166 + 5228264 + 299827, 100]
> {159252, 57}
> If you don't like this, you would be better off using a calculator watch.

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2016. All Rights Reserved.