Easy engineering notation
Project description
<p><img alt="Travis CI Build Status" src="https://travisci.org/slightlynybbled/engineering_notation.svg?branch=master" /></p>
<h1>Purpose</h1>
<p>To easily work with humanreadable engineering notation. I wrote this as a quick tool for my own use.
I found that I was writing the same functionality into multiple packages and would like a quick pipinstallable
package to take care of this manipulation for me. The package should be easily extended for other use cases.
The package is unitless, so only operates on numeric values. Unit detection may be added in future versions.</p>
<h1>Installation</h1>
<p>Install using pip: <code>pip install engineering_notation</code>.</p>
<h1>Status</h1>
<p>This project currently has 100% test coverage. Have a look in <code>test/test.py</code> for examples of how to use
this library.</p>
<h1>Use</h1>
<p>There are multiple ways of initializing a number to a particular value, but a string is the preferred method:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>from engineering_notation import EngNumber
EngNumber('10k')
10k
EngNumber('10000')
10k
EngNumber(10000)
10k
EngNumber(10000.0)
10k
EngNumber(1e4)
10k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Where decimals are involved, we use a default precision of 2 digits:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('4.99k')
4.99k
EngNumber('4.9k')
4.90k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>This behavior can truncate your results in some cases, and cause your number to round. To specify more or less
digits, simply specify the precision in the declaration:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('4.999k')
5k
EngNumber('4.999k', precision=3)
4.999k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Most operations that you would perform on numeric values are valid, although all operations are not implemented:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('2.2k') * 2
4.40k
2 * EngNumber('2.2k')
4.40k
EngNumber(1.2) > EngNumber('3.3k')
False
EngNumber(1.2) <= EngNumber('3.3k')
True
EngNumber('3.3k') == EngNumber(3300)
True
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>All of the above operations are also possible on the <code>EngUnit()</code> class as well. The only difference is
that units must match for addition/subtraction/comparison operations. Although multiplication and division
operations will work numerically, they may not always be strictly correct. This is because EngUnit is not
intended to replace a computer algebra system!</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngUnit('2s') / EngUnit('4rotations')
0.5s/rotations
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Additionally, since there are 'reserved' letters for sizing the number, you must be careful with your units!</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngUnit('2mm')
2mm # <<< this value equivalent to "0.002m"
EngUnit('2meter')
2meter # <<< this value is equivalent to "0.002eter", the "m" was used to scale the unit!
```</p>
</blockquote>
</blockquote>
</blockquote>
<h1>Contributions</h1>
<p>Contributions are welcome. Feel free to make feature requests in the issues.</p>
<h1>Purpose</h1>
<p>To easily work with humanreadable engineering notation. I wrote this as a quick tool for my own use.
I found that I was writing the same functionality into multiple packages and would like a quick pipinstallable
package to take care of this manipulation for me. The package should be easily extended for other use cases.
The package is unitless, so only operates on numeric values. Unit detection may be added in future versions.</p>
<h1>Installation</h1>
<p>Install using pip: <code>pip install engineering_notation</code>.</p>
<h1>Status</h1>
<p>This project currently has 100% test coverage. Have a look in <code>test/test.py</code> for examples of how to use
this library.</p>
<h1>Use</h1>
<p>There are multiple ways of initializing a number to a particular value, but a string is the preferred method:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>from engineering_notation import EngNumber
EngNumber('10k')
10k
EngNumber('10000')
10k
EngNumber(10000)
10k
EngNumber(10000.0)
10k
EngNumber(1e4)
10k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Where decimals are involved, we use a default precision of 2 digits:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('4.99k')
4.99k
EngNumber('4.9k')
4.90k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>This behavior can truncate your results in some cases, and cause your number to round. To specify more or less
digits, simply specify the precision in the declaration:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('4.999k')
5k
EngNumber('4.999k', precision=3)
4.999k
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Most operations that you would perform on numeric values are valid, although all operations are not implemented:</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngNumber('2.2k') * 2
4.40k
2 * EngNumber('2.2k')
4.40k
EngNumber(1.2) > EngNumber('3.3k')
False
EngNumber(1.2) <= EngNumber('3.3k')
True
EngNumber('3.3k') == EngNumber(3300)
True
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>All of the above operations are also possible on the <code>EngUnit()</code> class as well. The only difference is
that units must match for addition/subtraction/comparison operations. Although multiplication and division
operations will work numerically, they may not always be strictly correct. This is because EngUnit is not
intended to replace a computer algebra system!</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngUnit('2s') / EngUnit('4rotations')
0.5s/rotations
```</p>
</blockquote>
</blockquote>
</blockquote>
<p>Additionally, since there are 'reserved' letters for sizing the number, you must be careful with your units!</p>
<p>```</p>
<blockquote>
<blockquote>
<blockquote>
<p>EngUnit('2mm')
2mm # <<< this value equivalent to "0.002m"
EngUnit('2meter')
2meter # <<< this value is equivalent to "0.002eter", the "m" was used to scale the unit!
```</p>
</blockquote>
</blockquote>
</blockquote>
<h1>Contributions</h1>
<p>Contributions are welcome. Feel free to make feature requests in the issues.</p>
Project details
Release history Release notifications
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size engineering_notation0.2.0py3noneany.whl (6.9 kB)  File type Wheel  Python version py3  Upload date  Hashes View hashes 
Close
Hashes for engineering_notation0.2.0py3noneany.whl
Algorithm  Hash digest  

SHA256  6bb31ee2f56f5046bdd37ae1d0f7deb404a07e39354a83a0e445c793afec8e53 

MD5  54a5d093f09ecdc1f5bdb7fc56aa3461 

BLAKE2256  3026ce504427df5ffedd6e96bfcef72227ec10d00a30b8942918455da052dcc9 