title: Convert an amount to Indian Notation in Python
body: <p><strong>Problem:</strong> I need to convert an amount to Indian currency format</p>
  
  <p><strong>My code:</strong> I have the following <code>Python</code> implementation:</p>
  
  <pre><code>import decimal
  def currencyInIndiaFormat(n):
    d = decimal.Decimal(str(n))
    if d.as_tuple().exponent &lt; -2:
      s = str(n)
    else:
      s = '{0:.2f}'.format(n)
    l = len(s)
    i = l-1;
    res = ''
    flag = 0
    k = 0
    while i&gt;=0:
      if flag==0:
        res = res + s[i]
        if s[i]=='.':
          flag = 1
      elif flag==1:
        k = k + 1
        res = res + s[i]
        if k==3 and i-1&gt;=0:
          res = res + ','
          flag = 2
          k = 0
      else:
        k = k + 1
        res = res + s[i]
        if k==2 and i-1&gt;=0:
          res = res + ','
          flag = 2
          k = 0
      i = i - 1
  
    return res[::-1]
  
  def main():
    n = 100.52
    print "INR " + currencyInIndiaFormat(n)  # INR 100.52
    n = 1000.108
    print "INR " + currencyInIndiaFormat(n)  # INR 1,000.108
    n = 1200000
    print "INR " + currencyInIndiaFormat(n)  # INR 12,00,000.00
  
  main()
  </code></pre>
  
  <p><strong>My Question:</strong> Is there a way to make my <em>currencyInIndiaFormat</em> function <strong>shorter, more concise and clean</strong> ? / Is there a better way to write my <em>currencyInIndiaFormat</em> function ?</p>
  
  <p><strong>Note:</strong> My question is mainly based on <code>Python</code> implementation of the above stated problem. <em>It is not a duplicate of previously asked questions regarding conversion of currency to Indian format.</em></p>
  
  <p><strong>Indian Currency Format:</strong></p>
  
  <p>For example, numbers here are represented as:</p>
  
  <pre><code>1
  10
  100
  1,000
  10,000
  1,00,000
  10,00,000
  1,00,00,000
  10,00,00,000
  </code></pre>
  
  <p>Refer <a href="http://en.wikipedia.org/wiki/Indian_numbering_system" rel="noreferrer">Indian Numbering System</a></p>