Python Forum
Why replace treats an integer value 999 as 999.0?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why replace treats an integer value 999 as 999.0?
#5
(Feb-09-2020, 08:45 PM)new_to_python Wrote: So in Python, I don't need to do that explicitly and as long as two numbers (could both be float/double or one float/double and one integer) are close, they are considered to be the same?
Has to be very close if remove one 0 and it's False.
>>> 3 == 3.000000000000001
False
For better control on how close look at math.isclose() numpy also have numpy.isclose.
There also a decimal module where can better control over precision,
can eg do financial calculation or as a calculator would output.
>>> 0.1 * 3
0.30000000000000004
>>> from decimal import Decimal
>>> 
>>> result = Decimal('0.1') * Decimal('3')
>>> result
Decimal('0.3')
>>> print(result)
0.3
Pandas is a own big beast and can have other rules Undecided
Reply


Messages In This Thread
RE: Why replace treats an integer value 999 as 999.0? - by snippsat - Feb-09-2020, 11:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Search & Replace - Newlines Added After Replace dj99 3 3,437 Jul-22-2018, 01:42 PM
Last Post: buran
  Using a variable to replace an integer? (Except it isn't working!) s1monsays 15 8,470 Jul-25-2017, 06:58 PM
Last Post: s1monsays

Forum Jump:

User Panel Messages

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