-1

I have to convert this value to 23.69 or 23.70 not like that talll number 23.69098712446352

a=552.0
b=23.3
c=a/b
print(c)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
Ammar Alyasry
  • 106
  • 1
  • 6

3 Answers3

0

str.format the output:

print("{:.2f}".format(c))

Or round:

round(c, 2)

Output:

In [9]: print(c)
23.6909871245

In [10]: print("{:.2f}".format(c))
23.69
In [11]: print(round(c, 2))
23.69
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
0

Use round function -

c = round(a/b , 2)
Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
0

Two ways: round(a.b, 2)

Or just for display use this:

>>> "%.2f" % 3.14159
'3.14'
>>> print("%.2f" % a)
sinhayash
  • 2,693
  • 4
  • 19
  • 51