Repository: FreeCAD/FreeCAD
File: src/Mod/Measure/Gui/TaskMeasure.cpp (C++)

Code before:
    int unitIndex = unitSwitch->findText(unitFromResult);
    if (unitIndex >= 0) {
        QSignalBlocker unitSwitchBlocker(unitSwitch);
        unitSwitch->setCurrentIndex(unitIndex);

        mLastUnitSelection = unitFromResult;
    }
}

void TaskMeasure::updateResultWithUnit()
{
    if (!_mMeasureObject) {
        return;
    }

    QString resultString = _mMeasureObject->getResultString();
    QString currentUnit = unitSwitch->currentText();

    if (currentUnit != QLatin1String("-") && !resultString.isEmpty()) {
        Base::Quantity resultQty = Base::Quantity::parse(resultString.toStdString());
        // Parse unit string like "1 mm" to get the target quantity
        Base::Quantity targetUnit = Base::Quantity::parse(("1 " + currentUnit).toStdString());
        double convertedValue = resultQty.getValueAs(targetUnit);

        QString formattedValue;
        // 4 decimal places, if between -1 and 1 4 signfnificant digits
        if (std::abs(convertedValue) < 1.0 && convertedValue != 0.0) {
            formattedValue = QString::number(convertedValue, 'g', 4);
        }
        else {
            formattedValue = QString::number(convertedValue, 'f', 4);
        }

        QString formattedResult = formattedValue + " " + currentUnit;
        valueResult->setText(formattedResult);
    }
    else {
        valueResult->setText(resultString);
    }
}


void TaskMeasure::initViewObject(Measure::MeasureBase* measure)
{
    Gui::Document* guiDoc = Gui::Application::Instance->activeDocument();
    if (!guiDoc) {
        return;
    }

    Gui::ViewProvider* viewObject = guiDoc->getViewProvider(measure);
    if (!viewObject) {

Review comment (suggestion):
```suggestion
        // 4 decimal places, if between -1 and 1: 4 significant digits
```

Code after:
    int unitIndex = unitSwitch->findText(unitFromResult);
    if (unitIndex >= 0) {
        QSignalBlocker unitSwitchBlocker(unitSwitch);
        unitSwitch->setCurrentIndex(unitIndex);

        mLastUnitSelection = unitFromResult;
    }
}

void TaskMeasure::updateResultWithUnit()
{
    if (!_mMeasureObject) {
        return;
    }

    QString resultString = _mMeasureObject->getResultString();
    QString currentUnit = unitSwitch->currentText();

    if (currentUnit != QLatin1String("-") && !resultString.isEmpty()) {
        Base::Quantity resultQty = Base::Quantity::parse(resultString.toStdString());
        // Parse unit string like "1 mm" to get the target quantity
        Base::Quantity targetUnit = Base::Quantity::parse(("1 " + currentUnit).toStdString());
        double convertedValue = resultQty.getValueAs(targetUnit);

        QString formattedValue;
        // 4 decimal places, if between -1 and 1: 4 significant digits
        if (std::abs(convertedValue) < 1.0 && convertedValue != 0.0) {
            formattedValue = QString::number(convertedValue, 'g', 4);
        }
        else {
            formattedValue = QString::number(convertedValue, 'f', 4);
        }

        QString formattedResult = formattedValue + " " + currentUnit;
        valueResult->setText(formattedResult);
    }
    else {
        valueResult->setText(resultString);
    }
}


void TaskMeasure::initViewObject(Measure::MeasureBase* measure)
{
    Gui::Document* guiDoc = Gui::Application::Instance->activeDocument();
    if (!guiDoc) {
        return;
    }

    Gui::ViewProvider* viewObject = guiDoc->getViewProvider(measure);
    if (!viewObject) {