Python Forum
Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key
#3
It is worth noting that floats comparison needs additional care when performed.

Look at the following example:
1.3 / 3.9 == 13 / 39
Output:
False
This is due to the finite accuracy of representation float numbers in computer memory.
As of Python 3.5 (PEP-485), you can do such a comparison using math.isclose function.


import math
math.isclose(1.3 / 3.9, 13 / 39)
Output:
True
Reply


Messages In This Thread
RE: Comaparing Float Values of Dictionary Against A Float Value & Pick Matching Key - by scidam - Jul-25-2019, 11:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Using Lists as Dictionary Values bfallert 8 352 Apr-21-2024, 06:55 AM
Last Post: Pedroski55
  python calculate float plus float is incorrect? sirocawa 6 314 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Matching Data - Help - Dictionary manuel174102 1 411 Feb-02-2024, 04:47 PM
Last Post: deanhystad
  need to compare 2 values in a nested dictionary jss 2 880 Nov-30-2023, 03:17 PM
Last Post: Pedroski55
  Formatting float number output barryjo 2 934 May-04-2023, 02:04 PM
Last Post: barryjo
  Printing specific values out from a dictionary mcoliver88 6 1,429 Apr-12-2023, 08:10 PM
Last Post: deanhystad
  convert string to float in list jacklee26 6 1,935 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  TypeError: 'float' object is not callable #1 isdito2001 1 1,092 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  Write Null values as 0.0 (float) type in csv mg24 3 1,382 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 1,476 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov

Forum Jump:

User Panel Messages

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