from typing import Union


def squared_number(n: Union[int, float]) -> int:
    """
    Return square root of n if n is a perfect square using Babylonian algorithm.
    n must be a positive integer. Otherwise, if n is a positive float number,
    it must have zero decimal places.
    """
    if n < 1:
        raise ValueError("n must be a positive integer.")
    if isinstance(n, float) and not n.is_integer():  # type: ignore
        return 0

    x = n // 2
    if x == 0:
        if n == 1:
            return 1
        return 0

    cache = set((x,))
    while x * x != n:
        x = (x + (n // x)) // 2
        if x in cache:
            return 0
        cache.add(x)
    return int(x)