更新时间:2023-02-11 08:52:23
这正是 divmod
的发明目的:
How do you convert Decimal Degrees to Degrees Minutes Seconds In Python? Is there a Formula already written?
This is exactly what divmod
was invented for:
>>> def decdeg2dms(dd):
... mnt,sec = divmod(dd*3600,60)
... deg,mnt = divmod(mnt,60)
... return deg,mnt,sec
>>> dd = 45 + 30.0/60 + 1.0/3600
>>> print dd
45.5002777778
>>> decdeg2dms(dd)
(45.0, 30.0, 1.0)