I tried to run a code that returns a list of numbers with a value as the median value, b intervals, and in the middle, I found that there were different values than I expected, such as 27.700000000000003. I think it will be easy to solve, but I'm asking you because I'm curious about why this phenomenon occurs. I'd appreciate it if you could answer!
a = 28.1
b = 0.1
li = [a-5*b, a-4*b, a-3*b, a-2*b, a-1*b, a, a+1*b, a+2*b, a+3*b, a+4*b, a+5*b]
print(li)
Python says there is a limit to the accuracy of decimal division. I think the document says it's an error caused by floating point operations.
See Floating Point Arithmetic: Issues and Limitations.
© 2024 OneMinuteCode. All rights reserved.