1

Why does simple division by 10 results in such answers rather than shifting of a decimal place to the left? How can I shift decimal place to the left by using simple arithmetic operations in Python? repeated division of 3333333 by 10

PS: I am an absolute beginner to programming. So pardon me if it is too silly a question! Thanks in advance!

Community
  • 1
  • 1
  • Numbers aren't stored as lists of decimal digits. `33`, if you think of it as a list of anything, is the list of *binary* digits `100001` (so `2**5 + 2**0`, not `10**1 + 3*10**0`). There's no decimal point *to* shift. Division by *2*, on the other hand, can be implemented precisely by shifting the "binary point": since 10 is `1010`, 10/2 is simply `101`, or 5. – chepner Nov 14 '19 at 16:12

1 Answers1

0

Floating point numbers do not get represented precisely in computers. It is a complicated topic. You can start reading about it here

https://docs.python.org/3/tutorial/floatingpoint.html

https://floating-point-gui.de/

https://blog.demofox.org/2017/11/21/floating-point-precision/

MK.
  • 33,605
  • 18
  • 74
  • 111
  • A floating-point number is stored precisely, because what that term means is a number that is represented in a floating-point format: A sign, a sequence of digits, and an exponent (which is the floating part), with some minor such as variations on where the radix point is in the sequence of digits. When you have a floating-point number, you have the thing that is stored—it is precise, and it represents one number exactly. What you mean is that, when real numbers or decimal numerals are converted to a floating-point format, there is generally some loss of information during the conversion. – Eric Postpischil Nov 14 '19 at 19:47