-3

How do I change a number like 3.3 to 3.30 to represent currency in python? does this include using round()? The code running The code

I want the 5.3 to be 5.30 and if it is 2 I want it to be 2.00.

  • 1
    You should consider using integers for currency to avoid floating point rounding issues. – 001 Mar 12 '20 at 19:47
  • Does this answer your question? [Currency formatting in Python](https://stackoverflow.com/questions/320929/currency-formatting-in-python) – Fred Larson Mar 12 '20 at 19:51
  • Hi. In order to solve this question,could you tell us what exactly that you have tried. The Solution mentioned by @JohnnyMopp will work but it's best for you to tell the code that you have written in order to solve this issue. – Dhruv Marwha Mar 12 '20 at 19:52

1 Answers1

0

You should take a look at float string formatting documentaiton.

In your case this will work.

'{:.2f}'.format(3)
Michael Savchenko
  • 1,445
  • 1
  • 9
  • 13