We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ab19d82 + b683154 commit a4e9267Copy full SHA for a4e9267
test/test_value.py
@@ -286,3 +286,6 @@ def test_format() -> None:
286
x = 42.235 * tu.GHz
287
assert f'{x:0.2f}' == '42.23 GHz'
288
assert f'{x:0.1e}' == '4.2e+01 GHz'
289
+
290
+ assert f'{tu.GHz}' == 'GHz'
291
+ assert f'{2*tu.GHz}' == '2 GHz'
tunits/core/cython/with_unit.pyx
@@ -729,6 +729,7 @@ cdef class WithUnit:
729
self.base_units.__setstate__(pickle_info['base_units'])
730
731
def __format__(self, spec: str) -> str:
732
+ if spec == '' and self.value == 1: return str(self)
733
return self.value.__format__(spec) + ' ' + str(self.unit)
734
735
_try_interpret_as_with_unit = None
0 commit comments