From ea6ed77b3ed9d19a720dbbbd5db515f73843324b Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 29 Feb 2020 00:20:21 +0100 Subject: [PATCH] Base: [skip ci] improve repr() for quantity https://forum.freecadweb.org/viewtopic.php?f=10&t=43718 https://forum.freecadweb.org/viewtopic.php?f=10&t=43431&p=369556#p369575 --- src/Base/QuantityPyImp.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index c90dbbcee7..a1e3f1f7e2 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -36,10 +36,21 @@ using namespace Base; std::string QuantityPy::representation(void) const { std::stringstream ret; +#if 0 //ret.precision(getQuantityPtr()->getFormat().precision); //ret.setf(std::ios::fixed, std::ios::floatfield); ret << getQuantityPtr()->getValue() << " "; ret << getQuantityPtr()->getUnit().getString().toUtf8().constData(); +#else + double val= getQuantityPtr()->getValue(); + Unit unit = getQuantityPtr()->getUnit(); + + // Use Python's implementation to repr() a float + Py::Float flt(val); + ret << static_cast(flt.repr()); + if (!unit.isEmpty()) + ret << " " << unit.getString().toUtf8().constData(); +#endif return ret.str(); }