RE: Errors with decimal addition in Mathematica 5.0
- To: mathgroup at smc.vnet.net
- Subject: [mg47419] RE: [mg47416] Errors with decimal addition in Mathematica 5.0
- From: "Florian Jaccard" <florian.jaccard at eiaj.ch>
- Date: Sun, 11 Apr 2004 04:43:59 -0400 (EDT)
- Reply-to: <florian.jaccard at eiaj.ch>
- Sender: owner-wri-mathgroup at wolfram.com
Hello ! The last digit is correct. Mathematica automatically displays 6 significant digits. It is a good choice, because you wouldn't be able to apprciate more... However, you can have more digits displayed : one way is to use SetPrecision : In[4]:= SetPrecision[13505.5 - 244.91, 8] Out[4]= 13260.590 You can also use SetAccuracy if you want to specify how many digits you want to see after the decimal point. But you can also take time to think about the number-writing : You have to understand that when you write (by hand) 13505.5 , it does not meen 27011/2 , but 13505.5 with 6 significant digits. With Mathematica, you can specify that you have 7 significant digits if you write 13505.5`7 . So, you can obtain what you wish if you specify the number of significant digits of both of your numbers : In[18]:= 13505.5`7 - 244.91`5 Out[18]= 13260.59 Regards Florian Jaccard -----Message d'origine----- De : Peng Yu [mailto:yupeng_ at hotmail.com] Envoyé : sam., 10. avril 2004 08:01 À : mathgroup at smc.vnet.net Objet : [mg47416] Errors with decimal addition in Mathematica 5.0 In[1]:= 13505.5 - 244.91 Out[1]= 13260.6 However,13505.5 - 244.91 = 13260.59. "N" doesn't help, either. In[25]:= N[13505.50 - 244.91] Out[25]= 13260.6 But the following command gives the correct answer. In[26]:= 505.50 - 244.91 Out[26]= 260.59 How can I get the correct last digit? Thanks!