diff --git a/kcalc.cpp b/kcalc.cpp --- a/kcalc.cpp +++ b/kcalc.cpp @@ -1541,19 +1541,30 @@ void KCalculator::slotConstclicked(int button) { if(KCalcConstButton *btn = qobject_cast(const_buttons_[button])) { + // Constants are stored in a C locale way to ensure they can be read correctly + // by instances of KCalc with different locale settings. + const QChar localeCDecimalPoint(QLatin1Char('.')); + const QChar localeCGroupSeparator(QLatin1Char(',')); + const bool groupSeparatorEnabled = KCalcSettings::groupDigits() && + !(QLocale().numberOptions() & QLocale::OmitGroupSeparator); + if (!shift_mode_) { // set the display to the configured value of constant button - // internally, we deal with C locale style numbers, we need to convert QString val = btn->constant(); - val.replace(QLatin1Char('.'), KNumber::decimalSeparator()); + if (groupSeparatorEnabled) + val.remove(localeCGroupSeparator); + val.replace(localeCDecimalPoint, KNumber::decimalSeparator()); calc_display->setAmount(KNumber(val)); - } else { pbShift->setChecked(false); - // internally, we deal with C locale style numbers, we need to convert QString val = calc_display->text(); - val.replace(KNumber::decimalSeparator(), QLatin1String(".")); + for (QChar &c : val) { + if (c == KNumber::decimalSeparator()) + c = localeCDecimalPoint; + else if (groupSeparatorEnabled && (c == KNumber::groupSeparator())) + c = localeCGroupSeparator; + } KCalcSettings::setValueConstant(button, val); // below set new tooltip