Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Currency Style by elihro.duarte
import re
def checkio(text):
if re.search(r'\d{3}\.\d{3}\.\d{3}\.\d{3}', text): return text # This is a IP
text = re.sub(r'\,(?=\d{2}\b)', '.', text) # Replace decimal separator
text = re.sub(r'\.(?=\d{3}\b)', ',', text) # Replace thousands separator
return text
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio("$1.234.567,89") == "$1,234,567.89" , "1st Example"
assert checkio("$0,89") == "$0.89" , "2nd Example"
assert checkio("Euro Style = $12.345,67, US Style = $12,345.67") == \
"Euro Style = $12,345.67, US Style = $12,345.67" , "European and US"
assert checkio("Us Style = $12,345.67, Euro Style = $12.345,67") == \
"Us Style = $12,345.67, Euro Style = $12,345.67" , "US and European"
assert checkio("$1.234, $5.678 and $9") == \
"$1,234, $5,678 and $9", "Dollars without cents"
assert checkio("$4.545,45 is less than $5,454.54.") == \
"$4,545.45 is less than $5,454.54.", ""
assert checkio("127.255.255.255") == \
"127.255.255.255"
Nov. 2, 2017
Comments: