1

I got this number 1.12412 and I want to round it to 1.12415 or 1.12410 (muliple of 5 in last decimal)

If using the Round(X,4) function I get 1.1241 (4 decimals).

Is there a function that can make that happen? Thanks!

There is an answer in stack but using c# not python

Raphael Hen
  • 83
  • 1
  • 6

2 Answers2

5

My way to do that is to specify rounding unit first and then simple trick as below:

import numpy as np
rounding_unit = 0.00005
np.round(1.12412/rounding_unit) * rounding_unit
0

You may:

  1. Multiply your number by 2
  2. Use Round(X,4)
  3. Divide the result by 2
  4. profit!!!
lenik
  • 23,228
  • 4
  • 34
  • 43