1414import org .elasticsearch .common .io .stream .StreamOutput ;
1515import org .elasticsearch .common .io .stream .Writeable ;
1616import org .elasticsearch .common .logging .DeprecationLogger ;
17+ import org .elasticsearch .core .SuppressForbidden ;
1718import org .elasticsearch .xcontent .ToXContentFragment ;
1819import org .elasticsearch .xcontent .XContentBuilder ;
1920
@@ -213,10 +214,10 @@ public String toString() {
213214 }
214215
215216 /**
216- * Strictly speaking, this is only <em>guaranteed</em> to return the exact right two decimals
217+ * Strictly speaking, this is only <em>guaranteed</em> to return the exact right string
217218 * when {@code numerator} is the rounded value of some multiple of 1% of {@code denominator}.
218- * Other arbitrary values, where {@code numerator / denominator} exceeds the precision of a
219- * {@code double}, may be off by a little .
219+ * Other arbitrary values could yield surprising results; for example, you might see
220+ * {@code 123.0} or even {@code 1221.00} in place of {@code 123} .
220221 */
221222 static String format2Decimals (long numerator , long denominator ) {
222223 // If numerator >> denominator, we risk exceeding the precision of a double, so we enlist
@@ -231,7 +232,12 @@ static String format2Decimals(long numerator, long denominator) {
231232 }
232233 }
233234
234- private static final DecimalFormat MAX_TWO_DECIMALS = new DecimalFormat (".##" );
235+ private static final DecimalFormat MAX_TWO_DECIMALS = maxTwoDecimalsFormat ();
236+
237+ @ SuppressForbidden (reason ="We truly just want two decimals; Locale settings don't matter here" )
238+ private static DecimalFormat maxTwoDecimalsFormat () {
239+ return new DecimalFormat (".##" );
240+ }
235241
236242 public static ByteSizeValue parseBytesSizeValue (String sValue , String settingName ) throws ElasticsearchParseException {
237243 return parseBytesSizeValue (sValue , null , settingName );
@@ -322,7 +328,7 @@ private static ByteSizeValue parse(
322328 BigDecimal decimalValue = new BigDecimal (s );
323329 if (decimalValue .scale () > 2 ) {
324330 throw new ElasticsearchParseException (
325- "more than two decimal places in setting [{}]: [{}]" ,
331+ "more than two decimal places in setting [{}] with value [{}]" ,
326332 settingName ,
327333 initialInput
328334 );
0 commit comments