Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13049 > unrolled thread

Re: Precision

Started byAndrzej Kozlowski <akozlowski@gmail.com>
First post2013-01-07 05:36 +0000
Last post2013-01-07 05:36 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Precision Andrzej Kozlowski <akozlowski@gmail.com> - 2013-01-07 05:36 +0000

#13049 — Re: Precision

FromAndrzej Kozlowski <akozlowski@gmail.com>
Date2013-01-07 05:36 +0000
SubjectRe: Precision
Message-ID<kcdmse$m0j$1@smc.vnet.net>
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.


Andrzej Kozlowski



[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web