blob: 19bb8186cb41d7e07fd21718e712d53fde1e4a7b (
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
55
56
57
58
|
package org.singinst.uf.common;
import java.util.Collection;
import org.singinst.uf.math.MathUtil;
public class StringUtil {
// Show probabilities as 25.57% or 0.2557?
private static final boolean PROBABILITY_AS_PERCENTAGE = true;
// Decimal digits to show for probabilities (i.e. 2 => 25.57% or 0.26)
private static final int PROBABILITY_DECIMALS = 2;
// Decimal digits to show for multipliers (i.e. 2 => 3.44x)
private static final int MULTIPLIER_DECIMALS = 2;
public static String join(String delimiter, Collection<String> collection) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (String string : collection) {
if (!first) {
builder.append(delimiter);
}
first = false;
builder.append(string);
}
return builder.toString();
}
/**
* Format a probability value for display.
* @param p
* @return
* @author henrik
*/
public static String formatProbability(double p) {
String value;
if (PROBABILITY_AS_PERCENTAGE)
value = MathUtil.round(p * 100, PROBABILITY_DECIMALS) + "%";
else
value = MathUtil.round(p, PROBABILITY_DECIMALS) + "";
return value;
}
/**
* Format a multiplier value for display.
* @param v
* @return
* @author henrik
*/
public static String formatMultiplier(double v) {
return MathUtil.round(v, MULTIPLIER_DECIMALS) + "x";
}
}
|