+ 2
Wrong calculator?
Why this code outputs 5.3500000000000005 instead of 5.35? print(5.00 * 1.07) https://code.sololearn.com/cXBn8i7yNh3p/?ref=app
5 Respostas
+ 4
https://www.sololearn.com/discuss/3007535/?ref=app
https://www.sololearn.com/Discuss/1477626/?ref=app
+ 3
Yes. Use round method
print(round(5.00 * 1.07, 2) )
+ 2
# Hi, Amirreza Amiri !
# If you want to work with decimal numbers, and it is important for
# you to get correct decimal answers, then you can use Decimal from the
# decimal module:
from decimal import Decimal
x = Decimal('5')
y = Decimal('1.07')
print(x*y)
# gives: 5.35
# N.B. The numbers are in quotes (are strings), like ”1.07” .
+ 1
Jayakrishna🇮🇳 Thanks a lot.
Is there any way to get the 5.35 output? I only need two decimals.
+ 1
Thank you Per Bratthammar 🙏
It was a great method 👌