This question already has an answer here:

Mod[1.2, 0.2] is not equal to zero

2 answers

I have a math question which that may seem simple to some but not to me if you where to do the calculation 12.30 * 12 it would equal 147.60 but why is that when I show the answer to more then two decimal place it has a 2 at the end 147.60000000000002 where did the 2 come from if 12.30 is a whole number ?

Again Im sorry if this sounds dumb but Im curious and thought this is the best place to ask.

=================

=================

1 Answer

1

=================

It’s a numerical artifact that is due to finite precision of computer calculations. Indeed, when one computes

SetAccuracy[12.30*12, 15]

147.60000000000002

It’s notable that the input is in decimal system (at least the user thinks of it as such), but the computer uses its binary representation. For example, 110\frac{1}{10} is an exact number, but 0.1 has an infinite expansion when expressed in binary (i.e., 0.110=0.000110011001100110011001100110011…20.1_{10}=0.000110011001100110011001100110011…_2). Hence the computer never uses exactly 110\frac{1}{10} but a rounded number:

SetAccuracy[0.1, 20]

0.1000000000000000056

What you see above in the case of 12.30*12 is most likely a result of such rounding. It should be also noted that in most published materials, when some result is given to e.g. 20 decimal digits, in most cases it is not reasonable: in fact, every machine will give a slightly different output. The computation on two different computers (or different software) can give results different on the 15th or 12th or some other decimal place.

Thank you for this makes a lot of sense

– MrJoshFisher

Sep 6 at 14:40