forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultValueFormatter.java
More file actions
40 lines (32 loc) · 1013 Bytes
/
DefaultValueFormatter.java
File metadata and controls
40 lines (32 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.github.mikephil.charting.utils;
import java.text.DecimalFormat;
/**
* Default formatter used for formatting values. Uses a DecimalFormat with
* pre-calculated number of digits (depending on max and min value).
*
* @author Philipp Jahoda
*/
public class DefaultValueFormatter implements ValueFormatter {
/** decimalformat for formatting */
private DecimalFormat mFormat;
/**
* Constructor that specifies to how many digits the value should be
* formatted.
*
* @param digits
*/
public DefaultValueFormatter(int digits) {
StringBuffer b = new StringBuffer();
for (int i = 0; i < digits; i++) {
if (i == 0)
b.append(".");
b.append("0");
}
mFormat = new DecimalFormat("###,###,###,##0" + b.toString());
}
@Override
public String getFormattedValue(float value) {
// avoid memory allocations here (for performance)
return mFormat.format(value);
}
}