Home > Blockchain >  Rounding down numbers to the next lower .95
Rounding down numbers to the next lower .95

Time:01-09

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?

CodePudding user response:

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
  •  Tags:  
  • Related