Commit 4e8ded2e authored by SZPYRKA Jean-Luc's avatar SZPYRKA Jean-Luc

fixed value parsing in dtkWidgetsSpinBoxDouble

parent 3f806db1
......@@ -79,33 +79,42 @@ QString dtkWidgetsSpinBoxDoublePrivate::textFromValue ( double value ) const
double dtkWidgetsSpinBoxDoublePrivate::valueFromText ( const QString & text ) const
{
// truncate the input text to the right decimal
QString work_on = text;
QStringList mant_exp;
QString exponent;
// split mantisse / exponent
if ( this->scientific ) { // split mantisse + exp
mant_exp = text.split(QRegExp("e"));
work_on = mant_exp[0];
if ( mant_exp.size() > 1 ) {
exponent = mant_exp[1];
} else {
exponent = "0" ;
}
}
// truncate to the right decimal lenght
QStringList int_dec;
int_dec = work_on.split(QRegExp("\\."));
// truncate decimals
QString result;
if (int_dec.size() > 1) {
if ( int_dec[1].length() > this->decimals) {
int_dec[1] = int_dec[1].left(this->decimals);
}
result = int_dec[0] + "." + int_dec[1];
}
else {
result = int_dec[0] ;
}
QString result = int_dec[0] + "." + int_dec[1];
if ( this->scientific ) {
if (mant_exp.size() > 1) {
result += "e" + mant_exp[1];
}
else {
result += "e+0" ;
}
result += "e" + exponent;
}
double dblValue = result.toDouble();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment