Ticket #8389: DeskCalcRoundingProblem.patch

File DeskCalcRoundingProblem.patch, 1.4 KB (added by ahenriksson, 12 years ago)
  • src/apps/deskcalc/ExpressionTextView.cpp

    diff --git a/src/apps/deskcalc/ExpressionTextView.cpp b/src/apps/deskcalc/ExpressionTextView.cpp
    index 1c59b54..bfc5604 100644
    a b ExpressionTextView::SetValue(BString value)  
    273273                digit = (int)(value[offset]) - '0' + 1; // ascii to int + 1
    274274                if (digit != 10)
    275275                    break;
    276                 value.Remove(offset, 1);
     276                value[offset] = '0';
    277277            }
    278278            if (digit == 10) {
    279279                // carry over, shift the result
    ExpressionTextView::SetValue(BString value)  
    296296            } else {
    297297                // increase the current digit value with one
    298298                value[offset] = char(digit + 48);
     299
     300                // set offset to last digit
     301                offset = value.FindFirst('E');
     302                if (offset == B_ERROR)
     303                    offset = value.CountChars();
     304                offset--;
    299305            }
    300306        }
    301307
    302         // remove trailing zeros
    303         while (value[offset] == '0')
    304             value.Remove(offset--, 1);
     308        // clean up decimal part if we have one
     309        if (value.FindFirst('.') != B_ERROR) {
     310            // remove trailing zeros
     311            while (value[offset] == '0')
     312                value.Remove(offset--, 1);
    305313
    306         // there is no need to keep the period if no digits follow
    307         if (value[offset] == '.')
    308             value.Remove(offset, 1);
     314            // there is no need to keep the period if no
     315            // digits follow
     316            if (value[offset] == '.')
     317                value.Remove(offset, 1);
     318        }
    309319    }
    310320
    311321    // set the new value