Logo Search packages:      
Sourcecode: qcad version File versions  Download package

RS_String RS_Math::doubleToString ( double  value,
double  prec 
) [static]

Evaluates a mathematical expression and returns the result. If an error occured, ok will be set to false (if ok isn't NULL). Converts a double into a string which is as short as possible

value The double value
prec Precision e.g. a precision of 1 would mean that a value of 2.12030 will be converted to "2.1". 2.000 is always just "2").

Definition at line 284 of file rs_math.cpp.

References round().

Referenced by RS_Units::formatAngle(), RS_Units::formatDecimal(), RS_Units::formatEngineering(), and test().

      if (prec<1.0e-12) {
            std::cerr << "RS_Math::doubleToString: invalid precision\n";
            return "";

    RS_String ret;
    RS_String exaStr;
    int dotPos;
    int num = RS_Math::round(value / prec);

    exaStr = RS_Math::doubleToString(prec, 10);
    dotPos = exaStr.find('.');

    if (dotPos==-1) {
        ret.sprintf("%d", RS_Math::round(num*prec));
    } else {
        int digits = exaStr.length() - dotPos - 1;
        ret = RS_Math::doubleToString(num*prec, digits);

    return ret;

Generated by  Doxygen 1.6.0   Back to index