Magnitude Order
Project description
magorder
This library streamlines the conversion between different orders of magnitude, like transforming nm (nanometers) to meters, or kilobytes to gigabytes.
It is meant to provide a drop-in mechanism that is simple and consistent to manipulate such conversions.
Installation
Install it as usual:
pip install magorder
Dependencies
This library has no runtime dependencies.
Usage
To use the library:
# import the MagnitudeUnit class that meets your requirements
from magorder.stdsi import StdSIMagnitudeUnit
# create a magorder object, associated with an unit
mag = StdSIMagnitudeUnit("m")
# transform can convert from a different order of magnitude to the base unit
assert mag.transform(0.1, "km") == 100
assert mag.transform(100_000_000, "µm") == 100
assert mag.transform(100_000_000_000_000_000_000_000_000.0, "ym") == 100
assert mag.transform(0.0000000000000000000001, "Ym", decimals=3) == 100
Or to transform data units:
from magorder.data import SIDataMagnitudeUnit, IECDataMagnitudeUnit
mags = SIDataMagnitudeUnit("b")
assert mags.transform(1, "kb") == 1000
assert mags.transform(1, from_unit="Gb", to_unit="kb") == 1_000_000
mags = IECDataMagnitudeUnit("b")
assert mags.transform(1, "Kib") == 1024
assert mags.transform(4096, from_unit="Mib", to_unit="Gib") == 4
See the module tests for more examples.
License
Check the file LICENSE.
Contributions
Feel free to contribute to this code at:
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 magorder-0.20.tar.gz.
File metadata
- Download URL: magorder-0.20.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c70a499258c32da0eac23344fe2dcf17809c49412c627431a67877506439b8af
|
|
| MD5 |
bea92d0d420ec6688b72dccd9cbbf579
|
|
| BLAKE2b-256 |
abbb285ca4bf1a5e85fd605d7519a3c29fe97656a30bc8626c018a0821213b42
|
File details
Details for the file magorder-0.20-py3-none-any.whl.
File metadata
- Download URL: magorder-0.20-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cad03caf8baa9f2c7214272fb4726152c9bbb14962f7e192a45ae772fdadf0a1
|
|
| MD5 |
5acc13fa84d4a591bc8e426de9f5570c
|
|
| BLAKE2b-256 |
d24385640c648151597c994ac665c9486bd2bf9a698301e74d013e3dd334d6cc
|