Skip to content

Commit

Permalink
PercentFormatter: make space between number and percent sign optional
Browse files Browse the repository at this point in the history
  • Loading branch information
duchampdev committed Apr 27, 2019
1 parent ed8876c commit 0563fb4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 0563fb4

Please sign in to comment.