hrev43961 adds 1 changeset to branch 'master' old head: 9e4967aa9d166326e5f016dd9d768aa8e29116b2 new head: f7b9606639a2c3a7836e35472fe3c5946e55ba3e ---------------------------------------------------------------------------- f7b9606: Patch by ahenriksson to fix a computation bug in Deskcalc Ticket #8389 Signed off by John Scipione When trimming trailing 0's to make the number fit in the window, make sure to only trim trailing 0's AFTER the decimal point, not before. [ John Scipione <jscipione@xxxxxxxxx> ] ---------------------------------------------------------------------------- Revision: hrev43961 Commit: f7b9606639a2c3a7836e35472fe3c5946e55ba3e URL: http://cgit.haiku-os.org/haiku/commit/?id=f7b9606 Author: John Scipione <jscipione@xxxxxxxxx> Date: Fri Apr 6 20:50:27 2012 UTC Ticket: https://dev.haiku-os.org/ticket/8389 ---------------------------------------------------------------------------- 1 files changed, 18 insertions(+), 8 deletions(-) src/apps/deskcalc/ExpressionTextView.cpp | 26 ++++++++++++++++++-------- ---------------------------------------------------------------------------- diff --git a/src/apps/deskcalc/ExpressionTextView.cpp b/src/apps/deskcalc/ExpressionTextView.cpp index 1c59b54..c6b36ec 100644 --- a/src/apps/deskcalc/ExpressionTextView.cpp +++ b/src/apps/deskcalc/ExpressionTextView.cpp @@ -258,7 +258,7 @@ ExpressionTextView::SetValue(BString value) stringWidth = font.StringWidth(value); } - // there is no need to keep the period if no digits follow + // no need to keep the period if no digits follow if (value[offset] == '.') { value.Remove(offset, 1); offset--; @@ -273,7 +273,7 @@ ExpressionTextView::SetValue(BString value) digit = (int)(value[offset]) - '0' + 1; // ascii to int + 1 if (digit != 10) break; - value.Remove(offset, 1); + value[offset] = '0'; } if (digit == 10) { // carry over, shift the result @@ -296,16 +296,26 @@ ExpressionTextView::SetValue(BString value) } else { // increase the current digit value with one value[offset] = char(digit + 48); + + // set offset to last digit + offset = value.FindFirst('E'); + if (offset == B_ERROR) + offset = value.CountChars(); + offset--; } } - // remove trailing zeros - while (value[offset] == '0') - value.Remove(offset--, 1); + // clean up decimal part if we have one + if (value.FindFirst('.') != B_ERROR) { + // remove trailing zeros + while (value[offset] == '0') + value.Remove(offset--, 1); - // there is no need to keep the period if no digits follow - if (value[offset] == '.') - value.Remove(offset, 1); + // there is no need to keep the period if no + // digits follow + if (value[offset] == '.') + value.Remove(offset, 1); + } } // set the new value