我想将放入其中的数字格式化为浮点数、定点数到小数点后两位或三位。但是我的代码不起作用
class Quake:
"""Earthquake in terms of latitude, longitude, depth and magnitude"""
def __init__(self, lat, lon, depth, mag):
self.lat=lat
self.lon=lon
self.depth=depth
self.mag=mag
def __str__(self):
return "M{2.2f}, {3.2f} km, lat {3.3f}\N{DEGREE\
SIGN lon {3.3f}\N{DEGREE SIGN}".format(
self.mag, self.depth, self.lat, self.lon)
这会产生错误消息:
'AttributeError: 'float' object has no attribute '2f''