Skip to content

Commit 502e7c3

Browse files
authored
Merge pull request #516 from toburger/fix/invariant-culture
Make the decimal formatters culture invariant
2 parents 89c82a1 + 1ff1ec7 commit 502e7c3

File tree

1 file changed

+11
-3
lines changed
  • convex-core/src/main/java/convex/core/text

1 file changed

+11
-3
lines changed

convex-core/src/main/java/convex/core/text/Text.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.math.BigInteger;
44
import java.text.DecimalFormat;
5+
import java.text.DecimalFormatSymbols;
56
import java.time.Instant;
67
import java.time.format.DateTimeFormatter;
78
import java.time.format.DateTimeFormatterBuilder;
@@ -17,6 +18,13 @@ public class Text {
1718
private static final int WHITESPACE_LENGTH = 32;
1819
private static final String ZEROS_9 = "000000000";
1920
private static String WHITESPACE_32 = " "; // 32 spaces
21+
private static DecimalFormatSymbols symbols;
22+
23+
static {
24+
symbols = new DecimalFormatSymbols();
25+
symbols.setDecimalSeparator('.');
26+
symbols.setGroupingSeparator(',');
27+
}
2028

2129
/**
2230
* Return true if the character is an ASCII numeric digit
@@ -65,18 +73,18 @@ public static String rightPad(long value, int length) {
6573
return rightPad(Long.toString(value), length);
6674
}
6775

68-
static DecimalFormat balanceFormatter = new DecimalFormat("#,###");
76+
static DecimalFormat balanceFormatter = new DecimalFormat("#,###", symbols);
6977

7078
public static String toFriendlyNumber(long value) {
7179
return balanceFormatter.format(value);
7280
}
7381

74-
static DecimalFormat percentFormatter = new DecimalFormat("##.###%");
82+
static DecimalFormat percentFormatter = new DecimalFormat("##.###%", symbols);
7583
public static String toPercentString(double value) {
7684
return percentFormatter.format(value);
7785
}
7886

79-
static DecimalFormat decimalFormatter = new DecimalFormat("#,##0.####");
87+
static DecimalFormat decimalFormatter = new DecimalFormat("#,##0.####", symbols);
8088
public static String toFriendlyDecimal(double value) {
8189
if (!Double.isFinite(value)) return CVMDouble.create(value).toString();
8290
return decimalFormatter.format(value);

0 commit comments

Comments
 (0)