Skip to content

Instantly share code, notes, and snippets.

@MrCrap
Forked from solanoize/Format Rupiah di Python.md
Created August 28, 2017 11:09
Show Gist options
  • Save MrCrap/9c655af6c7ba39005d30c865d5d6cada to your computer and use it in GitHub Desktop.
Save MrCrap/9c655af6c7ba39005d30c865d5d6cada to your computer and use it in GitHub Desktop.
Format rupiah di Python
# rupiah.py
# ---------------

import locale

def rupiah_format(angka, with_prefix=False, desimal=2):
    locale.setlocale(locale.LC_NUMERIC, 'IND')
    rupiah = locale.format("%.*f", (desimal, angka), True)
    if with_prefix:
        return "Rp. {}".format(rupiah)
    return rupiah

Running

>>> import rupiah
>>> rupiah.rupiah_format(10000)
'10.000,00'
>>> rupiah.rupiah_format(10000, True)
'Rp. 10.000,00'
@patahgaming
Copy link

thenx bang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment