rounder: A Python package for rounding numbers in complex objects

Hi all! When you work with numbers and need to print them, more often than not you want to round them. You can use the built-in round() function:
However, when you want to round numbers in a more complex Python object, you need to be careful; you may also need to write a dedicated function to round numbers in this object, and you may need to update it if the object's structure changes. Now, you do not need to do that: use the rounder Python package instead. It will round numbers in any non-nested or nested Python object, using the following functions: * round_object(obj, digits), which rounds numbers in the object to a provided number of decimal digits * ceil_object(obj), which rounds numbers up to the nearest integer * floor_object(obj), which rounds numbers down to the nearest integer * signif_object(obj, digits), which rounds numbers to a number of significant digits So, for example:
The package offers also two other functions: * signif(x, digits), to round a number to significant digits * map_object(map_function, obj, use_copy=False) The latter function is a generalized function that applies callable map_function to all numbers in obj. Consider this simplistic example:
map_object(lambda x: x**2, {'a': 3, 'b': [1, 2, 3]}) {'a': 9, 'b': [1, 4, 9]}
The package works with objects of many different types, not only those shown above. It works under both Windows and Linux. You can install it from PyPi: $ pip install rounder You will learn more about it from its GitHub repo: https://github.com/nyggus/rounder. Happy rounding! Pozdrawiam, Marcin
participants (1)
-
Marcin Kozak