Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: Precision

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129365] Re: Precision
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Mon, 7 Jan 2013 23:07:20 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <kc8k2f$b17$1@smc.vnet.net>

On Jan 4, 11:17 pm, Rob Ryan <tio54... at 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



  • Prev by Date: Re: Cursor position on images
  • Next by Date: system of differential equations mathematica help
  • Previous by thread: Re: Precision
  • Next by thread: Re: Mathematica 9.0 : SIGSEGV / Linux