mpu.units¶
Module contents¶
Handle units - currently only currencies.
-
class
mpu.units.
Currency
(name, code, numeric_code, symbol, exponent, entities, withdrawal_date, subunits)[source]¶ Bases:
object
Currency base class which contains information similar to ISO 4217.
-
for_json
()¶ Return a JSON-serializable object.
-
-
class
mpu.units.
Money
(value: Union[str, fractions.Fraction, int, Tuple], currency: Union[str, mpu.units.Currency])[source]¶ Bases:
object
Unit of account.
- Parameters
value (Union[str, fractions.Fraction, int, Tuple]) –
currency (Currency or str) –
Examples
>>> rent = Money(500, 'USD') >>> '{:.2f,shortcode}'.format(rent) 'USD 500.00' >>> '{:.2f,postshortcode}'.format(rent) '500.00 USD' >>> '{:.2f,symbol}'.format(rent) '$500.00' >>> '{:.2f,postsymbol}'.format(rent) '500.00$' >>> '{:.2f}'.format(rent) '500.00 USD'
-
for_json
()¶ Return a JSON-serializable object.
Allowed operations with Money¶
Here you can see which operations are allowed by two Money objects of currencies (A and B):
Money A |
Operator |
Money A |
Money B |
int, Fraction |
---|---|---|---|---|
+ , - |
Money A |
N/A |
N/A |
|
* |
N/A |
N/A |
Money A |
|
/ |
N/A |
N/A |
N/A |
|
// |
Fraction |
N/A |
Money A |
|
>, >=, <, <= |
Bool |
N/A |
N/A |
|
== |
Bool |
False |
False |