Add 0 after the comma

0

I have a string str(owner.Vr_real).replace('.',',') that receives values of type:

  • 2045.5
  • 3040,45
  • 4042,05

Notice that the first number does not complete with 0 (ex: 2045,50). What function could I use to add 0 to the end? I tried to use zfill , but to no avail.

    
asked by anonymous 19.09.2017 / 23:26

1 answer

1

You need to take a look at String Formatting Operations .

I realize that you want to first change the dots per comma and then set the number of decimal places. I tell you to do the opposite. First set the number of decimal places and then transform the semicolons.

You should use:

str("%0.2f" % (owner.Vr_real)).replace('.',',')
    
19.09.2017 / 23:45