to_char(current_balance, 'FM9999999999999999D99')
From the docs:
FM: prefix fill mode (suppress padding
blanks and zeroes)
If you want a locale-specific currency symbol, try L
:
to_char(current_balance, 'FML9999999999999999D99')
L: currency symbol (uses locale)
Results from PG 8.4 against column called dbl
with value of 12345.678 where id = 1:
>>> import psycopg2
>>> conn = psycopg2.connect(host='localhost', database='scratch', user='',password='')
>>> c = conn.cursor()
>>> c.execute("select to_char(dbl, '9999999999999999D99') from practice where id = 1;")
>>> c.fetchall() # with padding
[(' 12345.68',)]
>>> c.execute("select to_char(dbl, 'FM9999999999999999D99') from practice where id = 1;")
>>> c.fetchall() # no padding
[('12345.68',)]
>>> c.execute("select to_char(dbl, 'FML9999999999999999D99') from practice where id = 1;")
>>> c.fetchall() # with locale-specific currency symbol
[('$12345.68',)]