From 62046f0518befbf870836fe3620bf0398d75999d Mon Sep 17 00:00:00 2001 From: andrewgsavage Date: Sat, 22 Jun 2024 10:45:18 +0100 Subject: [PATCH] add note on symbols to currency docs (#2023) --- docs/advanced/currencies.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/advanced/currencies.rst b/docs/advanced/currencies.rst index 26b66b531..addc94785 100644 --- a/docs/advanced/currencies.rst +++ b/docs/advanced/currencies.rst @@ -84,3 +84,16 @@ currency on its own dimension, and then implement transformations:: More sophisticated formulas, e.g. dealing with flat fees and thresholds, can be implemented with arbitrary python code by programmatically defining a context (see :ref:`contexts`). + +Currency Symbols +---------------- + +Many common currency symbols are not supported by the pint parser. A preprocessor can be used as a workaround: + +.. doctest:: + + >>> import pint + >>> ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("€", "EUR")]) + >>> ureg.define("euro = [currency] = € = EUR") + >>> print(ureg.Quantity("1 €")) + 1 euro