Skip to content
Open

Qstr #145

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gpkitmodels/tools/qstr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from gpkit.small_scripts import mag

def qstr(qty, fmtstr="%-.4g"):
'Converts a number/pint quantity to a nice string for display'
if hasattr(qty, "magnitude"):
magstr = fmt % qty.magnitude
unitstr = u" {:~}".format(qty.units)
if "dimensionless" in unitstr: # boring and long way to put it
unitstr = ""
return magstr + unitstr
else:
return fmt % qty # it's just a number