Skip to content

Commit

Permalink
[SS]Fix Integer Formatted Value
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Oct 2, 2019
1 parent ff5a978 commit bed78b0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/Mod/Spreadsheet/App/Cell.cpp
Expand Up @@ -992,14 +992,8 @@ std::string Cell::getFormattedQuantity(void)
}
}

} else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId()) ||
prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
double rawVal;
if(prop->isDerivedFrom(App::PropertyFloat::getClassTypeId())) {
rawVal = static_cast<const App::PropertyFloat*>(prop)->getValue();
} else {
rawVal = static_cast<const App::PropertyInteger*>(prop)->getValue();
}
} else if (prop->isDerivedFrom(App::PropertyFloat::getClassTypeId())){
double rawVal = static_cast<const App::PropertyFloat*>(prop)->getValue();
DisplayUnit du;
bool hasDisplayUnit = getDisplayUnit(du);
double duScale = du.scaler;
Expand All @@ -1008,6 +1002,17 @@ std::string Cell::getFormattedQuantity(void)
QString number = QLocale::system().toString(rawVal / duScale, 'f',Base::UnitsApi::getDecimals());
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
} else if (prop->isDerivedFrom(App::PropertyInteger::getClassTypeId())) {
double rawVal = static_cast<const App::PropertyInteger*>(prop)->getValue();
DisplayUnit du;
bool hasDisplayUnit = getDisplayUnit(du);
double duScale = du.scaler;
int iRawVal = std::round(rawVal);
qFormatted = QLocale::system().toString(iRawVal);
if (hasDisplayUnit) {
QString number = QLocale::system().toString(rawVal / duScale, 'f',Base::UnitsApi::getDecimals());
qFormatted = number + Base::Tools::fromStdString(" " + displayUnit.stringRep);
}
}
result = Base::Tools::toStdString(qFormatted);
return result;
Expand Down

0 comments on commit bed78b0

Please sign in to comment.