diff --git a/gpkitmodels/tools/qstr.py b/gpkitmodels/tools/qstr.py index bcd58608..f02f0ad6 100644 --- a/gpkitmodels/tools/qstr.py +++ b/gpkitmodels/tools/qstr.py @@ -1,5 +1,12 @@ from gpkit.small_scripts import mag -def qstr(qty): - 'Converts a pint quantity to a nice string for display' - return "%-.4g%s" % (qty.magnitude, u" {:~}".format(qty.units)) if hasattr(qty, "magnitude") else (qty, "") +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