如何将一个复数(例如1.9999999999999998-2j)取整为2-2j?
1.9999999999999998-2j
2-2j
当我尝试使用
print(round(x,2))
这显示了
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
将实部和虚部分别取整,然后将它们组合:
>>> num = 1.9999999999999998-2j >>> round(num.real, 2) + round(num.imag, 2) * 1j (2-2j)