Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Ray Koopman Posts: 3,383 Registered: 12/7/04
Re: Precision
Posted: Jan 7, 2013 11:05 PM

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}]

159253.
159253.
159253.
159253.00

Date Subject Author
1/5/13 PA32R
1/7/13 Nasser Abbasi
1/7/13 Richard Fateman
1/7/13 Ray Koopman