Skip to content

Commit

Permalink
Merge pull request PhilJay#4512 from duchampdev/percent_formatter_sig…
Browse files Browse the repository at this point in the history
…n_spacing

PercentFormatter: make space between number and percent sign optional
  • Loading branch information
PhilJay authored Apr 27, 2019
2 parents ed8876c + c5667d4 commit 2340e12
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* This IValueFormatter is just for convenience and simply puts a "%" sign after
* each value. (Recommeded for PieChart)
* each value. (Recommended for PieChart)
*
* @author Philipp Jahoda
*/
Expand All @@ -16,9 +16,11 @@ public class PercentFormatter extends ValueFormatter

public DecimalFormat mFormat;
private PieChart pieChart;
private boolean percentSignSeparated;

public PercentFormatter() {
mFormat = new DecimalFormat("###,###,##0.0");
percentSignSeparated = true;
}

// Can be used to remove percent signs if the chart isn't in percent mode
Expand All @@ -27,9 +29,15 @@ public PercentFormatter(PieChart pieChart) {
this.pieChart = pieChart;
}

// Can be used to remove percent signs if the chart isn't in percent mode
public PercentFormatter(PieChart pieChart, boolean percentSignSeparated) {
this(pieChart);
this.percentSignSeparated = percentSignSeparated;
}

@Override
public String getFormattedValue(float value) {
return mFormat.format(value) + " %";
return mFormat.format(value) + (percentSignSeparated ? " %" : "%");
}

@Override
Expand Down

0 comments on commit 2340e12

Please sign in to comment.