Skip to content

Commit

Permalink
Squashed 'libs/utils/' changes from 40225ecccc..a28f653460
Browse files Browse the repository at this point in the history
a28f653460 Merge pull request #33 from wordpress-mobile/merge/WordPress-Android/12569
6caa352edd Bumping utils version.
87167d8bbd Limit storage percentage to 100%

git-subtree-dir: libs/utils
git-subtree-split: a28f6534604076b152742b01d23d3c6d9b5a1d24
  • Loading branch information
oguzkocer committed Aug 7, 2020
1 parent 454736b commit 703f9f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WordPressUtils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ android {
buildToolsVersion '28.0.3'

defaultConfig {
versionName "1.26"
versionName "1.27"
minSdkVersion 18
targetSdkVersion 26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,25 @@ public static final String formatFileSize(long size, final String[] unitStrings)
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.25 returns 25%
*/
public static final String formatPercentage(double value) {
return formatPercentageLimit100(value, false);
}

/*
* returns the passed double percentage (0 to 1) formatted as an human readable percentage. Ex: 0.251 returns 25.1%
* if limit100 is true, it limits the percentage to 100%
*/
public static final String formatPercentageLimit100(double value, boolean limit100) {
double limit = 1.0001;

NumberFormat percentFormat = NumberFormat.getPercentInstance();
percentFormat.setMaximumFractionDigits(1);
return percentFormat.format(value);

if (limit100 && value > limit) {
value = limit;
}

String percentage = percentFormat.format(value);

return percentage;
}
}

0 comments on commit 703f9f3

Please sign in to comment.