支持案例
支持多种货币的不洁价格串;
处理千个分隔符和十进制分隔符:>>> Price.fromstring("Price: $119.00")
Price(amount=Decimal('119.00'), currency='$')>>> Price.fromstring("15 130 Р")
Price(amount=Decimal('15130'), currency='Р')>>> Price.fromstring("151,200 تومان")
Price(amount=Decimal('151200'), currency='تومان')>>> Price.fromstring("Rp 1.550.000")
Price(amount=Decimal('1550000'), currency='Rp')>>> Price.fromstring("Běžná cena 75 990,00 Kč")
Price(amount=Decimal('75990.00'), currency='Kč')
欧元符号用作任意小数点分隔符:>>> Price.fromstring("1,235€ 99")
Price(amount=Decimal('1235.99'), currency='€')>>> Price.fromstring("99 € 95 €")
Price(amount=Decimal('99'), currency='€')>>> Price.fromstring("35€ 999")
Price(amount=Decimal('35'), currency='€')
处理一些特殊情况:>>> Price.fromstring("Free")
Price(amount=Decimal('0'), currency=None)
当无法提取价格或货币时,对应
属性值设置为无:>>> Price.fromstring("")
Price(amount=None, currency=None)>>> Price.fromstring("Foo")
Price(amount=None, currency=None)>>> Price.fromstring("50% OFF")
Price(amount=None, currency=None)>>> Price.fromstring("50")
Price(amount=Decimal('50'), currency=None)>>> Price.fromstring("R$")
Price(amount=None, currency='R$')