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

Rounding down numbers to the next lower .95

I want to round a number to the next lower .95:

20.84 -> 19.95
31.40 -> 30.95
45.34 _> 44.95
57.47 -> 56.95

How can I do this?

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

>Solution :

Since it easy to round down to the next integer, you can do what you want like this:

  1. add 0.05
  2. round down to the next integer
  3. subtract 0.05 again

Step 1 is necessary to avoid converting e.g. 2.98 to 1.95.

In Python code:

def round_down_95(x):
    return int(x + 0.05) - 0.05
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