0

For web automation testing i am generating randint and convert it into % and inputing it into fields, and then checks that value appears correctly.

install_share = randint(1000, 9999) / 100
        install_share = str(install_share)
        install_share = install_share + "%"

the problem is, if random value will have 0 as it last symbol, then after devision it will loss last '0' after decimal

a = 1970 / 100
print (a) # 19.7, but i need 19.70

I've tried

a = 1970.00 / 100
print (a) # 19.7

a = float(1970) / float(100)
print (a) # 19.7

but each time i received same rounding.

1 Answers1

2
a = 1970/10 # a = 19.7
print("{:.02f}".format(a))
>>> 19.70
Asish M.
  • 2,588
  • 1
  • 16
  • 31