blob: c8834c3e453607676d642db9ecc96aae185366b2 (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
package com.github.mikephil.charting.formatter;
import java.text.DecimalFormat;
/**
* Created by philipp on 02/06/16.
*/
public class DefaultAxisValueFormatter extends ValueFormatter
{
/**
* decimalformat for formatting
*/
protected DecimalFormat mFormat;
/**
* the number of decimal digits this formatter uses
*/
protected int digits;
/**
* Constructor that specifies to how many digits the value should be
* formatted.
*
* @param digits
*/
public DefaultAxisValueFormatter(int digits) {
this.digits = 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);
}
/**
* Returns the number of decimal digits this formatter uses or -1, if unspecified.
*
* @return
*/
public int getDecimalDigits() {
return digits;
}
}
|