Skip to content

Commit

Permalink
Fix handling of zero and one in native string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Apr 15, 2019
1 parent ab49cb0 commit 86052af
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ - (void)performUpdate
CGFloat rounded = isAlpha ? round(val * 1000) / 1000 : round(val);
str = isAlpha ? [NSString stringWithFormat:@"%1.3f", rounded] : [NSString stringWithFormat:@"%1.0f", rounded];
} else {
str = [NSString stringWithFormat:@"%1f", val];
NSNumber *numberValue = [NSNumber numberWithDouble:val];
str = [numberValue stringValue];
}

[formattedText replaceCharactersInRange:[match range] withString:str];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ public void update() {
// round the opacity (4th column).
boolean isAlpha = i == 4;
int rounded = (int)Math.round(isAlpha ? val * 1000 : val);
mSOutputMatcher.appendReplacement(sb, isAlpha ? String.valueOf((double)rounded / 1000) : String.valueOf(rounded));
String num = Double.toString(isAlpha ? (double)rounded / 1000 : rounded);
mSOutputMatcher.appendReplacement(sb, num);
} else {
mSOutputMatcher.appendReplacement(sb, String.valueOf(val));
String num = val == 0 ? "0" : val == 1 ? "1" : Double.toString(val);
mSOutputMatcher.appendReplacement(sb, num);
}
}
mSOutputMatcher.appendTail(sb);
Expand Down

0 comments on commit 86052af

Please sign in to comment.