Py学习  »  Python

Python将货币字符串拆分为货币代码和金额

tendaitakas • 3 年前 • 927 次点击  

R15.49 to (R, 15.49)

ZAR15.49 to (ZAR, 15.49)

here 并实现了以下功能:

def splitCurrency(string):    
    match = re.search(r'([\D]+)([\d,]+)', string)
    output = (match.group(1), match.group(2).replace(',',''))
    return output

但我得到了(R,15)或(ZAR,15)。它忽略了小数点后的数字

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/99364
 
927 次点击  
文章 [ 1 ]  |  最新文章 3 年前