Wrong conversion expression if number has 0 in fractional part. Example 10,0.

Such numbers ignored and left untouched. This cause error in calculation.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-02-05 13:56:51 +02:00
parent 278c4e7ee8
commit e64e3a9044

View File

@ -1771,19 +1771,19 @@ QString VApplication::FormulaFromUser(const QString &formula)
QList<QString> nValues = numbers.values();
for (int i = 0; i < nKeys.size(); ++i)
{
loc = QLocale::system();
bool ok = false;
qreal d = loc.toDouble(nValues.at(i), &ok);
const qreal d = loc.toDouble(nValues.at(i), &ok);
if (ok == false)
{
qDebug()<<"Can't convert to double token"<<nValues.at(i);
continue;
}
if (qFloor (d) < d)
{
QLocale loc = QLocale(QLocale::C);
QString dStr = loc.toString(d);
loc = QLocale(QLocale::C);
const QString dStr = loc.toString(d);
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
int bias = nValues.at(i).length() - dStr.length();
const int bias = nValues.at(i).length() - dStr.length();
if (bias != 0)
{
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
@ -1791,8 +1791,6 @@ QString VApplication::FormulaFromUser(const QString &formula)
nValues = numbers.values();
}
}
}
}
return newFormula;
@ -1885,21 +1883,19 @@ QString VApplication::FormulaToUser(const QString &formula)
QList<QString> nValues = numbers.values();
for (int i = 0; i < nKeys.size(); ++i)
{
QLocale loc = QLocale(QLocale::C);
loc = QLocale(QLocale::C);
bool ok = false;
qreal d = loc.toDouble(nValues.at(i), &ok);
const qreal d = loc.toDouble(nValues.at(i), &ok);
if (ok == false)
{
qDebug()<<"Can't convert to double token"<<nValues.at(i);
continue;
}
if (qFloor (d) < d)
{
QLocale loc = QLocale::system();
QString dStr = loc.toString(d);
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
int bias = nValues.at(i).length() - dStr.length();
loc = QLocale::system();
const QString dStr = loc.toString(d);
newFormula.replace(nKeys.at(i), nValues.at(i).length(), dStr);
const int bias = nValues.at(i).length() - dStr.length();
if (bias != 0)
{
CorrectionsPositions(nKeys.at(i), bias, tokens, numbers);
@ -1908,7 +1904,6 @@ QString VApplication::FormulaToUser(const QString &formula)
}
}
}
}
return newFormula;
}