mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
NEW add jkqtp_roundToDigits()
This commit is contained in:
parent
2559097fd2
commit
11bafa52e4
@ -29,6 +29,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
|
||||
<li>NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API</li>
|
||||
<li>NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH</li>
|
||||
<li>NEW add JKQTPExpected datatype</li>
|
||||
<li>NEW add jkqtp_roundToDigits()</li>
|
||||
</ul></li>
|
||||
|
||||
<li>JKQTPlotter:<ul>
|
||||
|
@ -143,6 +143,24 @@ inline T jkqtp_roundTo(const double& v) {
|
||||
return static_cast<T>(round(v));
|
||||
}
|
||||
|
||||
/** \brief round a double \a v using round() to a given number of decimal digits
|
||||
* \ingroup jkqtptools_math_basic
|
||||
*
|
||||
* \param v the value to round and cast
|
||||
* \param decDigits number of decimal digits, i.e. precision of the result
|
||||
*
|
||||
* this is equivalent to
|
||||
* \code
|
||||
* round(v * pow(10.0,(double)decDigits))/pow(10.0,(double)decDigits);
|
||||
* \endcode
|
||||
*
|
||||
* \callergraph
|
||||
*/
|
||||
inline double jkqtp_roundToDigits(const double& v, const int decDigits) {
|
||||
const double fac=pow(10.0,(double)decDigits);
|
||||
return round(v * fac) / fac;
|
||||
}
|
||||
|
||||
/** \brief round a double \a v using ceil() and convert it to a specified type T (static_cast!)
|
||||
* \ingroup jkqtptools_math_basic
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user