Skip to content

Commit

Permalink
Base: [skip ci] improve repr() for quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 28, 2020
1 parent 1cb4625 commit 9c154f7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Base/QuantityPyImp.cpp
Expand Up @@ -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<std::string>(flt.repr());
if (!unit.isEmpty())
ret << " " << unit.getString().toUtf8().constData();
#endif

return ret.str();
}
Expand Down

2 comments on commit 9c154f7

@vocx-fc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berndhahnebach, @sliptonic Hey, notice that since this commit some unit tests from FEM and Path fail because some strings are printed with different precision. Say, you are comparing '25' against '25.0', or '76.2' against '76.19999'. It's not a big deal but I presume now you have to write quantities with a fixed number of decimals.

@berndhahnebach
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.