Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to overcome a precision error in Python3 when summing a list of floating point numbers?

$
0
0

In Python3, 0.35 * 10 does not show the same result as summing a list of 10 numbers 0.35.

Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53) [Clang 6.0 (clang-600.0.57)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> 0.35 * 103.5>>> a = [0.35 for i in range(0, 10)]>>> sum(a)3.5000000000000004

Is it possible to overcome this precision error with Python3 alone? By that I mean without using libraries like numpy.


Viewing all articles
Browse latest Browse all 23131

Trending Articles