File tree Expand file tree Collapse file tree 2 files changed +9
-8
lines changed
Expand file tree Collapse file tree 2 files changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -554,14 +554,12 @@ NB_MODULE(units_llnl_ext, mod)
554554 .def (
555555 " __format__" ,
556556 [](const units::precise_measurement& measurement,
557- std::string fmt_string) {
557+ std::string fmt_string)-> std ::string {
558558 std::string result;
559559 if (fmt_string.empty ()) {
560560 result = units::to_string (measurement);
561561 } else if (fmt_string == " -" ) {
562- result = units::to_string (
563- units::precise_measurement (
564- measurement.value (), units::precise::one));
562+ result = std::to_string (measurement.value ());
565563 } else if (fmt_string.front () == ' -' ) {
566564 auto target_unit =
567565 units::unit_from_string (fmt_string.substr (1 ));
@@ -576,9 +574,7 @@ NB_MODULE(units_llnl_ext, mod)
576574 " Units are not compatible with given measurement " +
577575 fmt_string.substr (1 ));
578576 }
579- result = units::to_string (
580- units::precise_measurement (
581- new_value, units::precise::one));
577+ result = std::to_string (new_value);
582578 } else {
583579 auto target_unit = units::unit_from_string (fmt_string);
584580 if (!units::is_valid (target_unit)) {
Original file line number Diff line number Diff line change @@ -265,11 +265,16 @@ def test_format():
265265 assert "kg" in s1
266266
267267 s2 = f"the measurement is { m1 :-} "
268- assert s2 == "the measurement is 9.7552 "
268+ assert s2 == "the measurement is 9.755200 "
269269
270270 s3 = f"the measurement is { m1 :-kg} "
271271 assert "kg" not in s3
272272
273+ m3 = u .Measurement ("3.4" )
274+
275+ s4 = f"the measurement is { m3 :-} "
276+ assert "3.4" in s4
277+
273278
274279def test_format_error ():
275280 m1 = u .Measurement ("9.7552 lb" )
You can’t perform that action at this time.
0 commit comments