-1

How do I round off to the 2nd decimal point while doing the calculations inside a print statement?

temp = float(input("Input temperature in Fahrenheit to be converted to Celcius: "))
print((5/9)*(temp - 32))
ProgDarcy
  • 1
  • 1

2 Answers2

1

For example:

>>> print("%.2f" % 16.25667)
16.26
crayxt
  • 2,367
  • 2
  • 12
  • 17
1

You can use round() function for this purpose. It is more easy to understand.

First argument of this function is the floating point result or equivalent expression.

Second argument is the position till which you want to round off.

temp = float(input("Input temperature in Fahrenheit to be converted to Celcius: "))
print(round((5/9)*(temp - 32),2))

This is working code and I tested it.

amrs-tech
  • 485
  • 2
  • 14