Python Forum
Giving all possible values to four different variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Giving all possible values to four different variables
#7
(Jan-17-2021, 10:28 PM)bowlofred Wrote: Beware floating point math. Many decimals cannot be represented exactly. Either check for approximate solutions, or do your math with integers and then divide by 10 later. Otherwise you will run into problems.

>>> 0.3 + 0.3 + 0.3 + 0.1 == 1.0
False
Workaround 1
>>> 3 + 3 + 3 + 1 == 10
True
Workaround 2
>>> 0.99 < 0.3 + 0.3 + 0.3 + 0.1 < 1.01
True
Workaround 3
>>> decimal.Decimal('0.3') + decimal.Decimal('0.3') + decimal.Decimal('0.3') + decimal.Decimal('0.1') == decimal.Decimal('1.0')
True

Many thanks, I did not notice that before!!!
Reply


Messages In This Thread
RE: Giving all possible values to four different variables - by quest_ - Jan-17-2021, 11:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,529 Jul-27-2022, 08:50 PM
Last Post: rob101
  Create array of values from 2 variables paulo79 1 1,115 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  variables vcnt, ocnt, and mcnt adding previous values and not resetting to 0 archanut 2 1,962 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  Variables being overridden to initial values. p2bc 6 2,645 Oct-10-2020, 09:03 PM
Last Post: p2bc
  Print variable values from a list of variables xnightwingx 3 2,656 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Assign dynamic values to Variables srikanthpython 6 3,443 Jun-06-2020, 03:36 PM
Last Post: srikanthpython
  Using Excel Values As Variables for Equation dezmund 1 2,209 May-09-2019, 01:06 PM
Last Post: heiner55
  How many variables/values are limited to single assignment operator? Prabakaran141 1 2,053 Sep-06-2018, 03:32 PM
Last Post: Larz60+
  Storing and using UI variables values across files xenas 5 4,309 Mar-24-2017, 11:23 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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