hgrecco / pint

Operate and manipulate physical quantities in Python
http://pint.readthedocs.org/
Other
2.4k stars 472 forks source link

Compact Currency Formatting #1774

Open YousefEZ opened 1 year ago

YousefEZ commented 1 year ago

Hi I'm having trouble understanding how to patch into how string formatting for a particular Unit. For more context I want to be able to render Currencies in compact form because the quantities that I am dealing with are in the millions, and billions. I wanted the string format to pass through babel.numbers.format_compacy_currency. Is there a potential way of doing this atm?

MichaelTiemannOSC commented 1 year ago

I would love to know!

keewis commented 1 year ago

I don't think there's support for this right now (so you'd have to call your own function to format), but this would be a use case for the custom quantity formatters we've been discussing in #1357.

I'm unlikely to work on those myself, but I would review a PR (and help with refactoring the formatting code, since that's most likely necessary).

hgrecco commented 1 year ago

I have this idea of moving all formating options to a "delegate" (basically using composition over inheritances for this type of things) Then, people would be able to hack they own formatters and plug them without changing the hierarchy. Ideas?