libb.nearest

nearest(num, decimals)[source]

Round number to the nearest tick value.

Useful for eliminating float errors after arithmetic operations.

Parameters:
  • num (float) – Number to round.

  • decimals (float) – Tick size to round to.

Returns:

Rounded number.

Return type:

float

Example:

>>> nearest(401.4601, 0.01)
401.46
>>> nearest(401.46001, 0.0000000001)
401.46001