0

What is a good way to format a python decimal like this way?

115 --> 115.00

And

4,224 --> 4,224.00

1
  • If you have another question, the correct way is to ask a new question, not to edit your old question into something entirely different. Commented Apr 1, 2019 at 12:58

1 Answer 1

1

If you're using python 3.6+, a good option is f-strings:

f'{115:,.2f}'
f'{4224:,.2f}'

If the 4224 is actually a string (maybe because of the comma), you will need to transform it to a number before f"{int('4,224'.replace(',','')):,.2f}"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.