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: 4   Last Post: Jan 7, 2013 11:05 PM

 Messages: [ Previous | Next ]
 Tomas Garza Hernandez Posts: 264 Registered: 4/15/05
Re: Precision
Posted: Jan 7, 2013 12:36 AM

Since you're dealing with dollars and cents you don't have to worry about precision. Do your operations in the conventional way, and at the end, for purposes of viewing or printing your final result, use NumberForm:
In[1]:= 103971.66 + 52282.64 + 2998.27

Out[1]= 159253.
In[2]:= NumberForm[103971.66+52282.64+2998.27, {8,2}]
Out[2]//NumberForm= 159252.57
You can also ask for some other type of display, like inserting commas:
In[3]:= NumberForm[103971.66+52282.64+2998.27, {8,2}, DigitBlock->3]
Out[3]//NumberForm= 159,252.57
Check the OnLine Help browser or the tutorial on output formats for numbers.
-Tomas
> Subject: Precision
> From: tio540s1@gmail.com
> To: mathgroup@smc.vnet.net
> Date: Sat, 5 Jan 2013 02:19:25 -0500
>
> 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!

Date Subject Author
1/7/13 Andrzej Kozlowski
1/7/13 Tomas Garza Hernandez
1/7/13 Murray Eisenberg