diff --git a/src/Base/QuantityPy.xml b/src/Base/QuantityPy.xml index 328c354899..f4c487157b 100644 --- a/src/Base/QuantityPy.xml +++ b/src/Base/QuantityPy.xml @@ -48,6 +48,14 @@ Quantity(string) -- arbitrary mixture of numbers and chars defining a Quantity + + + +Return the Integral closest to x, rounding half toward even. +When an argument is passed, work like built-in round(x, ndigits). + + + Numeric Value of the Quantity (in internal system mm,kg,s) diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 1e1772dd48..c90dbbcee7 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -205,6 +205,17 @@ PyObject* QuantityPy::getValueAs(PyObject *args) return new QuantityPy(new Quantity(quant)); } +PyObject * QuantityPy::__round__ (PyObject *args) +{ + double val= getQuantityPtr()->getValue(); + Unit unit = getQuantityPtr()->getUnit(); + Py::Float flt(val); + Py::Callable func(flt.getAttr("__round__")); + double rnd = static_cast(Py::Float(func.apply(args))); + + return new QuantityPy(new Quantity(rnd, unit)); +} + PyObject * QuantityPy::number_float_handler (PyObject *self) { if (!PyObject_TypeCheck(self, &(QuantityPy::Type))) {