Calculation result after the decimal point in Python

Calculation after the decimal point is strange

It seems that the decimal point number of Python uses the rule "IEEE754 floating point number", so the calculation result of the decimal point is as follows ... It is a specification!

>>> 0.1 + 0.1 + 0.1
0.30000000000000004

There seems to be a way to use the Decimal module to return the correct calculation result. It is a calculation example with "no rounding error" after the decimal point ↓

>>> from decimal import *

>>> Decimal('0.1') + Decimal('0.1') + Decimal('0.1')
Decimal('0.3')

Recommended Posts

Calculation result after the decimal point in Python
Display n digits after the decimal point in python
Show decimal point in Python
The result of installing python in Anaconda
View the result of geometry processing in Python
Python decimal point handling
Date calculation in python
Date calculation in Python
Experience the good calculation efficiency of vectorization in Python
Omit the decimal point of the graph scale in matplotlib
Get the result in dict format with Python psycopg2
Download the file in Python
Find the difference in Python
Shapley value calculation in Python
Measure the execution result of the program in C ++, Java, Python.
The result of Java engineers learning machine learning in Python www
After enabling the python virtual environment in the batch file, run the python file
Quantum chemistry calculation in Python (Psi4)
Python in the browser: Brython's recommendation
Save the binary file in Python
Hit the Sesami API in Python
Get the desktop path in Python
Accelerometer Alan Variance Calculation in Python
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Hit the web API in Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
Get the host name in Python
Access the Twitter API in Python
The first step in Python Matplotlib
I wrote the stack in Python
Master the weakref module in Python
I compared the calculation time of the moving average written in Python
Learn the design pattern "Prototype" in Python
Learn the design pattern "Builder" in Python
The most sought after programming language in 2020
Try using the Wunderlist API in Python
Check the behavior of destructor in Python
Implemented in python after understanding the phenomenon that various probability distributions occur
Learn the design pattern "Flyweight" in Python
Try using the Kraken API in Python
Learn the design pattern "Observer" in Python
Learn the design pattern "Memento" in Python
Learn the design pattern "Proxy" in Python
Write the test in a python docstring
Learn the design pattern "Command" in Python
OR the List in Python (zip function)
Display Python 3 in the browser with MAMP
Tweet using the Twitter API in Python
Learn the design pattern "Visitor" in Python
Check the in-memory bytes of a floating point number float in Python
Learn the design pattern "Bridge" in Python
Check if the URL exists in Python
Learn the design pattern "Mediator" in Python
Associate the table set in python models.py
Learn the design pattern "Decorator" in Python
Run the Python interpreter in a script