我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用locale.atoi()。
def cast(self, value): try: return super(IntegerType, self).cast(value) except DefaultCastNotMacthed: pass try: value = float(value) except: return locale.atoi(value) if value.is_integer(): return int(value) else: raise ValueError('Invalid integer: %s' % value)
def __init__(self, currency, amount): self.currency = currency self.amount = locale.atoi(amount)
def cast(self, value): if value in ('', None): return None try: value = float(value) except: return locale.atoi(value) if value.is_integer(): return int(value) else: raise ValueError('Invalid integer: %s' % value)
def parse_price(price): # eg: u'$237,000,000' --> 237000000 if not price: return 0 return locale.atoi(re.sub('[^0-9,]', "", price))