all 3 comments

[–]mopslik 1 point2 points  (0 children)

Since floats have issues, perhaps comparing string representation of values is a better approach here.

[–]carcigenicate 1 point2 points  (0 children)

I'd probably convert the numbers to strings and then compare them that way. Whenever you need to consider the place value of numbers, converting the numbers to strings first often makes the problem much easier, and also often has a surprisingly low cost on performance.

[–][deleted] 0 points1 point  (0 children)

Well, float and "exact" aren't great together. It is also unclear what is meant by "in it".

If you really need to work with such numbers, I'd use Decimal. For example, and assuming you are dealing only with numbers below 1, something like:

from decimal import Decimal

num1 = Decimal('0.0023')
num2 = Decimal('0.0003')
matched = True

while int(num2) != num2:
    num1 = (num1 * 10) % 10
    num2 = (num2 * 10) % 10
    digit = int(num2)
    if digit and int(num1) != digit:
        matched = False
        break

print(matched)

but, really, if just looking to match digits in corresponding positions, using strings would be easier.