File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -279,3 +279,13 @@ def test_pick_roundtrip() -> None:
279279 x = value * unit
280280 s = pickle .dumps (x )
281281 assert x == pickle .loads (s )
282+
283+
284+ def test_format () -> None :
285+ x = 0.4234324 * tu .ns
286+ assert f'{ x :0.2f} ' == '0.42 ns'
287+ assert f'{ x :e} ' == '4.234324e-01 ns'
288+
289+ x = 42.235 * tu .GHz
290+ assert f'{ x :0.2f} ' == '42.23 GHz'
291+ assert f'{ x :0.1e} ' == '4.2e+01 GHz'
Original file line number Diff line number Diff line change @@ -704,6 +704,9 @@ cdef class WithUnit:
704704 self .display_units.__setstate__(pickle_info[' display_units' ])
705705 self .base_units.__setstate__(pickle_info[' base_units' ])
706706
707+ def __format__ (self , spec: str ) -> str:
708+ return self.value.__format__(spec ) + ' ' + str(self.unit )
709+
707710_try_interpret_as_with_unit = None
708711_is_value_consistent_with_default_unit_database = None
709712def init_base_unit_functions(
You can’t perform that action at this time.
0 commit comments