1

When we round off using python is there a way we get answer in 2 decimal place incase if:

round(10.3,2) 

It will give 10.3.Is there way so that we get 10.30?

  • 7
    10.30 is not 10.3 rounded up. It's a question of how much precision you are using to display the number. If you want to see 10.30, you need to use the proper output format statement to show 2 decimal places. – lurker Jun 27 '20 at 20:56

1 Answers1

1

10.3 is the same number as 10.30 so rounding has nothing to do with it. Try string formatting.

n = 10.3

"{:.2f}".format(n)  # classic str.format
f"{n:.2f}"          # f-strings in 3.6+
Adam Smith
  • 52,157
  • 12
  • 73
  • 112
  • 3
    *Save yourself some frustration and avoid trying to answer questions which... ...have already been asked and answered many times before.* https://stackoverflow.com/help/how-to-answer – kaya3 Jun 27 '20 at 20:58