-1

I am trying to round numbers up in python 3. In my existing code, the number either round up to the nearest 10 or down. For example, 67 goes to 70 and 64 goes to 60. I would like the number to always round up to the nearest multiple of 10, so that 67-->70 and 64-->70. Here is my code for rounding so far:

##ROUNDING SumOfUsrinput TO NEAREST 10##
SumOfUsrinput=int(input("Please enter the sum: "))
SumRounded=round(SumOfUsrinput,-1)
print (SumRounded)

I would appreciate it if you could answer simple and explain how it works.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
lewis12642
  • 23
  • 2
  • 8

1 Answers1

0

One way of rounding up would be to use integer division to go down to the precision you want and then multiplying back up. e.g.,:

Sumrounded = SumOfusrinput // (-10) * (-10)
2ps
  • 15,099
  • 2
  • 27
  • 47
Daniel
  • 42,087
  • 4
  • 55
  • 81