So I have a total, say 24, I need my code to find the nearest hightest multiple of 10. This would be 30 of course, so I need the code to calculate (30-24). If the number is 20 it would be 20 beucase it is equal to a highest muliple of 10. I then need to store the result for later use.
Asked
Active
Viewed 37 times
1 Answers
1
>>> def nh(val):
... return 9 - ((val + 9) % 10)
...
>>> nh(24)
6
>>> nh(20)
0

Ignacio Vazquez-Abrams
- 776,304
- 153
- 1,341
- 1,358
-
I don't fully understand – Mister Chief May 14 '16 at 20:10
-
@MisterChief: You don't actually need to know exactly *what* the next highest value is, you just need to know how far along towards it you are. – Ignacio Vazquez-Abrams May 14 '16 at 20:18
-
This seems to work, But what is this calculating? (gtin_total + 9) // 10 * 10 - gtin_total – Mister Chief May 14 '16 at 21:09