Skip to content

MrThearMan/round2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Round half away from zero.

pip install round2

Since python's default round function uses 'bankers rounding', I made this small module that uses 'commercial rounding' instead. This means half is rounded up for positive numbers and down for negative numbers:

>>> from round2 import round2
>>> round2(1.5)
2
>>> round2(2.5)
3
>>> round2(-1.5)
-2
>>> round2(-2.5)
-3
>>> round2(2.5, decimals=1)
2.5

If decimals=0 (default), returns an int, otherwise a float, just like Python’s round function.

Implemented in Cython with type hinting in Python.

Releases

No releases published

Packages

No packages published