Re: Precision

• To: mathgroup at smc.vnet.net
• Subject: [mg129380] Re: Precision
• From: Andrzej Kozlowski <akozlowski at gmail.com>
• Date: Thu, 10 Jan 2013 02:20:13 -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: <20130105071925.AC08868CA@smc.vnet.net>,<20130107053854.E0C86690A@smc.vnet.net> <BLU173-W2999E3DA79DF05397E36B1D0240@phx.gbl>

```Well, no. For large enough numbers the final cents will be rounded, e.g.

NumberForm[1234500000990000 + 12345.98, {16, 2}, ExponentFunction -> (Null &)]
1234500001002346.00

QuotientRemainder[1234500000990000 + 1234598, 100]

{12345000022245, 98}

Of course Murray was right; this won't be a problem unless you want to compute the US national debt up to cent or something of this kind. However, note also another problem, which also will come up when the number involved become large,  the need to use the option ExponentFunction. Without it you get:

NumberForm[1234500000990000 + 12345.98, 30]

1.234500001002346*10^(15)

As for your last question, the answer is simple: Mathematica is not Excel. If you want to do this sort of computations the way you would do in grade school use Excel or a pocket calculator.

Andrzej Kozlowski

On 8 Jan 2013, at 19:02, Kenneth Ramsey <ramsey2879 at msn.com> wrote:

> I think number form will always give the correct answer but drop ending zeros from the cents.  That is 751.60  -> "751.6" and 751.00 -> "751."   Don't know how to get around that., but I think it is better than QuotientRemainder which forces you to type in the final zeros in the cents. Excel allows you to chose the number of decimal places in the number. Why isn't that so with Mathematical?
>
>> From: akozlowski at gmail.com
>> Subject: Re: Precision
>> To: mathgroup at smc.vnet.net
>> Date: Mon, 7 Jan 2013 00:38:54 -0500
>>
>>
>> On 5 Jan 2013, at 08:19, Rob Ryan <tio540s1 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!
>>
>>
>> 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 atch.
>>
>>
>> Andrzej Kozlowski
>>
>
>>
>>

```

• References: