Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to define a number interval and then round up

I started trying:

(date.minute + 1) % 5

Later, I discovered that date.minute is not necessarily continuous. After 03 minutes, it is not necessarily 04 minutes. It may jump directly to 06 minutes.

So I need to be evenly divisible by 5 as the interval, and then count upwards.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For example, if the interval is 5, replace 6 with 5, 9 with 5, 10 with 10, and 14 with 10.

>Solution :

Try utilizing floor division i.e., // 5:

>>> testcases = [6, 9, 10, 14]
>>> for tc in testcases:
...     print(f'{tc} -> {tc // 5 * 5}')
... 
6 -> 5
9 -> 5
10 -> 10
14 -> 10
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading