#coding:utf-8class RoundFloat(object): def __init__(self,val): assert isinstance(val, float),"value must be a float" self.value = round(val,2) def __str__(self): return "{:.2f}".format(self.value) __repr__ = __str__ #def __repr__(self): # return self.__str__() r = RoundFloat(3.1567)print rprint type(r) output result:
3.16
<class ‘__main__.RoundFloat‘>
时间: 2024-10-23 01:23:23