Python Forum
why is there an unexpected maths result from a float calculation?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is there an unexpected maths result from a float calculation?
#4
Basic Answers
For financial calculation use decimal module.
from decimal import Decimal

pennies = input('Enter pennies: ')
dollars = Decimal(pennies) * Decimal('.01')
print(f'{pennies} pennies are worth ${dollars:.2f} in dollars')
print(dollars) 
Output:
Enter pennies: 35 35 pennies are worth $0.35 in dollars 0.35
Reply


Messages In This Thread
RE: unexpected math resule - by Yoriz - Jun-08-2019, 10:15 AM
RE: unexpected math resule - by Gribouillis - Jun-08-2019, 10:18 AM
RE: why is there an unexpected maths result from a float calculation? - by snippsat - Jun-09-2019, 08:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Maths and python: Compute stress level cheerful 1 3,432 Oct-20-2021, 10:05 AM
Last Post: Larz60+
  Increasing difficulty of a maths game Maxxy_Gray 1 4,139 Apr-04-2018, 03:00 PM
Last Post: sparkz_alot
  Making maths .py program faster Shutcois 1 3,282 Feb-16-2018, 06:39 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020