Replace toDouble by "replace(".", "")" to avoid bad double conversion

This commit is contained in:
Grégory Soutadé 2012-05-27 17:41:20 +02:00
parent 3ea0167b70
commit a987c09d5d
4 changed files with 6 additions and 6 deletions

View File

@ -772,12 +772,12 @@ void AccountPanel::OnOperationModified()
void AccountPanel::OnAccountModified(int row, int column)
{
User* user = _kiss->GetUser();
double amount;
int amount;
int id = user->GetAccountId(_accounts[row]);
if (_inModification || column != ACCOUNT_INIT) return;
amount = _accountsGrid->item(row, column)->text().toDouble();
amount = _accountsGrid->item(row, column)->text().replace(".", "").toInt();
_kiss->SetAccountAmount(id, _curMonth, _curYear, amount*100);
_accountsInitValues[id] = amount;

View File

@ -32,7 +32,7 @@ void FloatDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
QLineEdit *line = qobject_cast<QLineEdit *>(editor);
QString s ;
bool ok;
double value = line->text().toDouble(&ok);
double value = line->text().replace(".", "").toInt(&ok);
if (ok)
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", value)));
}

View File

@ -69,7 +69,7 @@ void FormulaDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
}
else
{
res = value.toDouble(&ok);
res = value.replace(".", "").toInt(&ok);
if (ok)
model->setData(index, qVariantFromValue(s.sprintf("%.2lf", res)));
}

View File

@ -961,7 +961,7 @@ void GridAccount::OnOperationModified(int row, int col)
value = item(row, DEBIT)->text();
if (value.length())
{
new_op.amount = value.toDouble()*100;
new_op.amount = value.replace(".", "").toInt();
if (new_op.amount < 0)
{
new_op.amount *= -1.0;
@ -975,7 +975,7 @@ void GridAccount::OnOperationModified(int row, int col)
value = item(row, CREDIT)->text();
if (value.length())
{
new_op.amount = value.toDouble()*100;
new_op.amount = value.replace(".", "").toInt();
if (new_op.amount < 0)
{
new_op.amount *= -1.0;