Last active
June 16, 2016 02:35
-
-
Save victorono/ef1d4764efa575a466673d8690c87667 to your computer and use it in GitHub Desktop.
format currency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def format_currency(value, decimal_points=3, seperator=u'.', money=u'$'): | |
value = str(value) | |
if len(value) <= decimal_points: | |
return value | |
parts = [] | |
while value: | |
parts.append(value[-decimal_points:]) | |
value = value[:-decimal_points] | |
parts.reverse() | |
value = "%s %s" % (money, seperator.join(parts)) | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment