diff options
author | Hans Boehm <hboehm@google.com> | 2016-07-25 13:37:09 -0700 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2016-07-25 13:37:09 -0700 |
commit | 762266e587b15a7145ff6671a1a63aea7949d67c (patch) | |
tree | 959e46c671f675bb638e7d2b169a4f8474310d99 /src/com/android/calculator2/Evaluator.java | |
parent | f5170192807702c65653d2fdbeb83f23463117d8 (diff) | |
download | android_packages_apps_ExactCalculator-762266e587b15a7145ff6671a1a63aea7949d67c.tar.gz android_packages_apps_ExactCalculator-762266e587b15a7145ff6671a1a63aea7949d67c.tar.bz2 android_packages_apps_ExactCalculator-762266e587b15a7145ff6671a1a63aea7949d67c.zip |
Add digit separators to pre-evaluated results
Bug: 30362853
I missed this one additional case in which we need to add digit
separators. This fix is relatively easy, since we ignore the
length added by digit separators when deciding how many digits to
display. SHORT_TARGET_LENGTH is only a heuristic anyway.
Change-Id: I5abed5d0d5c29a46089f619adcda3f1ecc7fe686
Diffstat (limited to 'src/com/android/calculator2/Evaluator.java')
-rw-r--r-- | src/com/android/calculator2/Evaluator.java | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java index 6667878..33960ba 100644 --- a/src/com/android/calculator2/Evaluator.java +++ b/src/com/android/calculator2/Evaluator.java @@ -677,7 +677,7 @@ class Evaluator { } if (msdIndex > dotIndex) { if (msdIndex <= dotIndex + EXP_COST + 1) { - // Preferred display format inthis cases is with leading zeroes, even if + // Preferred display format in this case is with leading zeroes, even if // it doesn't fit entirely. Replicate that here. msdIndex = dotIndex - 1; } else if (lsdOffset <= SHORT_TARGET_LENGTH - negative - 2 @@ -697,7 +697,8 @@ class Evaluator { final int totalDigits = lsdIndex - msdIndex + negative + 1; if (totalDigits <= SHORT_TARGET_LENGTH && dotIndex > msdIndex && lsdOffset >= -1) { // Fits, no exponent needed. - return negativeSign + cache.substring(msdIndex, lsdIndex + 1); + final String wholeWithCommas = StringUtils.addCommas(cache, msdIndex, dotIndex); + return negativeSign + wholeWithCommas + cache.substring(dotIndex, lsdIndex + 1); } if (totalDigits <= SHORT_TARGET_LENGTH - 3) { return negativeSign + cache.charAt(msdIndex) + "." @@ -706,8 +707,10 @@ class Evaluator { } // We need to abbreviate. if (dotIndex > msdIndex && dotIndex < msdIndex + SHORT_TARGET_LENGTH - negative - 1) { - return negativeSign + cache.substring(msdIndex, - msdIndex + SHORT_TARGET_LENGTH - negative - 1) + KeyMaps.ELLIPSIS; + final String wholeWithCommas = StringUtils.addCommas(cache, msdIndex, dotIndex); + return negativeSign + wholeWithCommas + + cache.substring(dotIndex, msdIndex + SHORT_TARGET_LENGTH - negative - 1) + + KeyMaps.ELLIPSIS; } // Need abbreviation + exponent return negativeSign + cache.charAt(msdIndex) + "." |