Python Online Compiler & Playground
HTML/CSS/JavaScript
HTML
CSS
Javascript
C++
C
PHP
Java
Python
Swift
C#
Ruby
Node.JS
Kotlin
jQuery
Go
R
TypeScript
Start Python Course
Register
using `decimal` module for higher precission
0
Author: Lothar
Dark
Public
Save
PY
py
1
2
3
4
5
6
7
8
from
decimal
import
Decimal
# Avoiding floating point issues
float_result =
0.1
+
0.2
print
(
"Using float:"
,
float_result
)
decimal_result = Decimal
(
'0.1'
)
+ Decimal
(
'0.2'
)
print
(
"Using Decimal:"
,
decimal_result
)
Enter to Rename, Shift+Enter to Preview
OUTPUT