A smart rounding library that rounds numbers from right to left
Project description
RoundAI
A smart rounding library that rounds numbers from right to left, providing more intuitive behavior than Python's built-in round() function in certain cases.
Installation
pip install roundai
Usage
from roundai import roundai
# Basic rounding
print(roundai(123.456789, 3)) # -> 123.457
print(roundai(123.456789, 2)) # -> 123.46
print(roundai(123.456789, 1)) # -> 123.5
# Key differences from built-in round():
print(roundai(2.5, 0)) # -> 3 (Standard rounding)
print(round(2.5)) # -> 2 (Python's "round to even")
# Preserves original if fewer decimals
print(roundai(123.4, 3)) # -> 123.4 (Preserves original)
print(round(123.4, 3)) # -> 123.400 (Adds trailing zeros)
# Consistent rounding from rightmost digit
x = 1.23454999999
y = 1.23460000000
print(roundai(x, 4)) # -> 1.2346 (Consistently rounds from right)
print(roundai(y, 4)) # -> 1.2346 (Stable for small changes)
Features
- Rounds numbers from right to left, propagating changes
- More intuitive behavior than Python's built-in round()
- Preserves original precision when possible
- Consistent rounding behavior for similar numbers
- No trailing zeros added
- Uses standard rounding rules (rounds up for .5)
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/BackFlipAI/roundai.git
cd roundai
# Install development dependencies
pip install -e ".[test]"
Running Tests
To run the tests:
pytest
For test coverage:
pytest --cov=roundai
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Run the test suite to ensure everything works
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file roundai-0.1.0.tar.gz.
File metadata
- Download URL: roundai-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9da6e8f82c8b7cb3c53c91ea4f347c5c08ac075d0ba702783a1328d73c39c3e
|
|
| MD5 |
b67ae853f587247adc0db714a2073a28
|
|
| BLAKE2b-256 |
431d76e1ce90a76fc475172da6899403d675fe564cbf752d681e5f8978310d72
|
File details
Details for the file roundai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: roundai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
715db9070a53ee648d548054a2c792203c0784c816cc7b0e1cd8759eb90b0bc2
|
|
| MD5 |
521415636856eb39e716c4c393cb4a51
|
|
| BLAKE2b-256 |
f08c4cf1311f2471c48653c5de47271d4fbe870f32dc52f017e2f0e2c64b9409
|