[Python] How to round up a complex number?

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    How can I round up a complex number (e.g. 1.9999999999999998-2j) as 2-2j?

    When I tried using

    print(round(x, 2))


    it showed

    Traceback (most recent call last):
    File "C:\Python34\FFT.py", line 22, in <module>
    print(round(x, 2))
    TypeError: type complex doesn't define __round__ method


    That's Python 3.4. I also tried in Python 2 and got TypeError: can't convert complex to float

    Continue reading...

Compartilhe esta Página