Skip to content

Commit cfc43df

Browse files
fhassakjyemin
authored andcommitted
[JAVA-2625] Set the character used for decimal separator (#420)
JAVA-2625: Set the character used for decimal separator so that it is no longer locale-sensitive.
1 parent c8aa973 commit cfc43df

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

driver-core/src/main/com/mongodb/connection/ServerDescription.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.bson.types.ObjectId;
2424

2525
import java.text.DecimalFormat;
26+
import java.text.DecimalFormatSymbols;
2627
import java.util.Collections;
2728
import java.util.Date;
2829
import java.util.HashSet;
@@ -50,6 +51,8 @@ public class ServerDescription {
5051

5152
private static final int DEFAULT_MAX_DOCUMENT_SIZE = 0x1000000; // 16MB
5253

54+
private static final DecimalFormatSymbols DECIMAL_FORMAT_SYMBOLS = initializeDecimalFormatSymbols();
55+
5356
private final ServerAddress address;
5457

5558
private final ServerType type;
@@ -78,6 +81,18 @@ public class ServerDescription {
7881

7982
private final Throwable exception;
8083

84+
/**
85+
* Initialize the character used for decimal separator
86+
*
87+
* @return the character used for decimal separator
88+
* @since 3.6
89+
*/
90+
private static DecimalFormatSymbols initializeDecimalFormatSymbols() {
91+
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
92+
decimalFormatSymbols.setDecimalSeparator('.');
93+
return decimalFormatSymbols;
94+
}
95+
8196
/**
8297
* Gets a Builder for creating a new ServerDescription instance.
8398
*
@@ -912,7 +927,7 @@ private String translateExceptionToString() {
912927

913928

914929
private String getRoundTripFormattedInMilliseconds() {
915-
return new DecimalFormat("#0.0").format(roundTripTimeNanos / 1000.0 / 1000.0);
930+
return new DecimalFormat("#0.0", DECIMAL_FORMAT_SYMBOLS).format(roundTripTimeNanos / 1000.0 / 1000.0);
916931
}
917932

918933
ServerDescription(final Builder builder) {

0 commit comments

Comments
 (0)