-1

I am simply trying to execute the following command in Python:

print("Number is", format(49000.12345,"10.2f"))

So I would like it to print out like 49,000.12 for the number.

My teacher taught us to put a comma in "10.2f" like ",10.2f" for the thousands separator but it's not working. Could someone please tell me the correct simple way similar to that?

Thank you

pschueller
  • 4,362
  • 2
  • 27
  • 50
user3301642
  • 19
  • 1
  • 1
  • @Cilyan What I don't get is, if I do ",.2f" it would work but when I do ",10.2f" it doesn't. Please could someone just show me an example at least? – user3301642 Feb 12 '14 at 13:23
  • 1
    According to the fomat specification mini-language page, the syntax is `format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]`. As you see the comma is expected right before the point. Try `"10,.2f"`. – Cilyan Feb 12 '14 at 15:37

1 Answers1

-2

See this: http://www.python.org/dev/peps/pep-0378/ It is the PEP introducing the ability into Python 2.7, 3.1 and later versions.

Paddy3118
  • 4,704
  • 27
  • 38