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


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

Precision

Started byRob Ryan <tio540s1@gmail.com>
First post2013-01-05 07:17 +0000
Last post2013-01-08 04:05 +0000
Articles 4 — 4 participants

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


Contents

  Precision Rob Ryan <tio540s1@gmail.com> - 2013-01-05 07:17 +0000
    Re: Precision "Nasser M. Abbasi" <nma@12000.org> - 2013-01-07 05:35 +0000
    Re: Precision Richard Fateman <fateman@cs.berkeley.edu> - 2013-01-07 05:36 +0000
    Re: Precision Ray Koopman <koopman@sfu.ca> - 2013-01-08 04:05 +0000

#13025 — Precision

FromRob Ryan <tio540s1@gmail.com>
Date2013-01-05 07:17 +0000
SubjectPrecision
Message-ID<kc8k2f$b17$1@smc.vnet.net>
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!

[toc] | [next] | [standalone]


#13042

From"Nasser M. Abbasi" <nma@12000.org>
Date2013-01-07 05:35 +0000
Message-ID<kcdmqv$lvi$1@smc.vnet.net>
In reply to#13025
On 1/5/2013 1:17 AM, Rob Ryan 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?

SetOptions[$FrontEndSession, PrintPrecision -> 16]

In[43]:= 103971.66+52282.64+2998.27
Out[43]= 159252.57

--Nasser

[toc] | [prev] | [next] | [standalone]


#13048

FromRichard Fateman <fateman@cs.berkeley.edu>
Date2013-01-07 05:36 +0000
Message-ID<kcdms9$m0f$1@smc.vnet.net>
In reply to#13025
On 1/4/2013 11:17 PM, Rob Ryan wrote:
> My frustration is growing. I simply want to add (for example):
> 103971.66+52282.64+2998.27.


InputForm[103971.66+52282.64+2998.27]  gives  159252.56999999998

If you don't like that, use the calculator on your phone (or watch?  do 
people still have watches? Such big ones?)


If this all seems mysterious, read up on floating-point binary numbers .



[toc] | [prev] | [next] | [standalone]


#13058

FromRay Koopman <koopman@sfu.ca>
Date2013-01-08 04:05 +0000
Message-ID<kcg5u2$rdg$1@smc.vnet.net>
In reply to#13025
On Jan 4, 11:17 pm, Rob Ryan <tio54...@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!

If you want the cents to *always* print, use PaddedForm with an
explicit request for 2 digits to the right of the decimal point.

s = 103971.66 + 52282.64 + 2998.27
NumberForm[s,8]

159253.
159252.57

t = s + .43
NumberForm[t,8]
NumberForm[t,{8,2}]
PaddedForm[t,{8,2}]

159253.
159253.
159253.
 159253.00

[toc] | [prev] | [standalone]


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


csiph-web