Skip to content

How to ensure a subclassed Quantity instance always renders trailing zeros to a given degree of precision #29

Closed Answered by KenKundert
jeffwright13 asked this question in Q&A
Discussion options

You must be logged in to vote

The first example in Subclasing Quantities gives an example of how to do this:

>>> class Watt(Quantity):
...     units = 'W'
...     prec = 2
...     strip_zeros = False

... pwr=Watt(0)
... print(pwr)
0.00 W

If you are formatting quantities for output in tables, you might want to also take a look at Formatting Tabular Data.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@jeffwright13
Comment options

Answer selected by KenKundert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants