0
$\begingroup$

I want to add two arrays length and Apice, It's accuracy to six decimal places. When I use NumberForm in Table I can get normal display results.

L = Table[NumberForm[length[[i]] + Apice[[i]], {20, 6}], {i, 1, 63, 2}]

enter image description here

But if I don't use NumberForm, It only shows six digits.

L1 = Table[length[[i]] + Apice[[i]], {i, 1, 63, 2}]

enter image description here

And if I copy it, some of the data gets weird like 1738.7604379999998 `, but shouldn't it be accurate to six decimal places? Why does this happen?

enter image description here

Two table I used as below:

length = {200.000000, 212.115008, 225.868224, 242.378091, 257.828801, 
   272.097053, 288.473261, 302.301205, 317.722170, 328.294180, 
   341.219205, 354.796398, 365.059240, 380.752053, 393.884689, 
   409.720935, 422.491637, 436.821486, 451.583677, 465.562686, 
   480.832709, 494.209854, 517.194735, 532.293884, 545.823898, 
   557.184369, 576.162592, 592.980488, 608.876434, 621.865923, 
   636.938468, 651.753063, 663.431800, 666.319720, 677.400281, 
   686.410644, 697.074233, 700.348906, 707.746790, 712.203767, 
   715.053581, 721.561347, 724.549487, 725.797116, 728.979858, 
   729.081471, 733.814231, 735.237762, 738.475131, 741.799661, 
   741.771007, 742.562259, 744.025644, 747.807148, 750.559859, 
   751.632473, 752.804419, 755.629828, 756.577273, 756.870575, 
   758.172753, 759.441409, 761.056067};

Apice = {10.000000, 422.115008, 432.115008, 900.361323, 910.361323, 
   1440.287177, 1450.287177, 2041.061643, 2051.061643, 2697.077993, 
   2707.077993, 3403.093596, 3413.093596, 4158.904889, 4168.904889, 
   4972.510513, 4982.510513, 5841.823636, 5851.823636, 6768.969999, 
   6778.969999, 7754.012562, 7764.012562, 8813.501181, 8823.501181, 
   9926.509448, 9936.509448, 11105.652528, 11115.652528, 12346.394885,
    12356.394885, 13645.086416, 13655.086416, 14984.837936, 
   14994.837936, 16358.648861, 16368.648861, 17766.072000, 
   17776.072000, 19196.022557, 19206.022557, 20642.637485, 
   20652.637485, 22102.984088, 22112.984088, 23571.045417, 
   23581.045417, 25050.097410, 25060.097410, 26540.372202, 
   26550.372202, 28034.705468, 28044.705468, 29536.538260, 
   29546.538260, 31048.730592, 31058.730592, 32567.164839, 
   32577.164839, 34090.612687, 34100.612687, 35618.226849, 
   35628.226849};
$\endgroup$
12
  • 1
    $\begingroup$ NumberForm is only a tag for printing, it does not change the underlying number. The default is 6 digits. If a tick (NumberMark) is shown is specified by: $NumberMark $NumberMark=Automatic/True/False. It indicates precision. $\endgroup$ Apr 8, 2021 at 7:28
  • $\begingroup$ As Daniel said, in Mathematica one distinguishes the internal representation of numbers, matrices, etc., and the displayed form. The latter is only for us, humans, convenience and should not be used for copy-pasting. Use assignment instead of copying. $\endgroup$
    – yarchik
    Apr 8, 2021 at 8:11
  • $\begingroup$ @ Daniel Huber @yarchik Thanks for you two replies, But why the numbers likes 1738.7604379999998 ' appeared? All of my data are to six decimal places, shouldn't they add up to six decimal places too? $\endgroup$
    – shrocat
    Apr 8, 2021 at 13:51
  • $\begingroup$ Most probably, you are dealing with numbers in machine precision (~15 decimal digits), they are more accurate than just 6 digits. $\endgroup$
    – yarchik
    Apr 8, 2021 at 13:54
  • 1
    $\begingroup$ Floating-point is binary and does not represent all decimal numbers exactly. Two half-bit rounding errors in the same direction can add up to a one-bit error. For instance, compare FullForm[0.6 + 0.7] with FullForm[1.3]. The rounding errors may be inspected like this, SetPrecision[0.6, Infinity] - 6/10. (Keep in mind that there are potentially three rounding errors in 0.6 + 0.7, two for converting the input decimals to floating-point numbers and one more for the sum.) — This is one reason for decimal computers seem better for human culture, but binary is more efficient electronically. $\endgroup$
    – Michael E2
    Apr 14, 2021 at 16:53

0

Browse other questions tagged or ask your own question.