"com.ibm.icu.text.DecimalFormat.SkipExtendedSeparatorParsing", "false")
.equals("true");
+ // allow control of requiring a matching decimal point when parsing
+ boolean parseRequireDecimalPoint = false;
// When parsing a number with big exponential value, it requires to transform the
// value into a string representation to construct BigInteger instance. We want to
}
}
+ if(digits.decimalAt == 0 && isDecimalPatternMatchRequired()) {
+ if(this.formatPattern.indexOf(decimal) != -1) {
+ parsePosition.setIndex(oldStart);
+ parsePosition.setErrorIndex(position);
+ return false;
+ }
+ }
+
if (backup != -1)
position = backup;
public boolean isDecimalSeparatorAlwaysShown() {
return decimalSeparatorAlwaysShown;
}
+
+ /**
+ * When decimal match is not required, the input does not have to
+ * contain a decimal mark when there is a decimal mark specified in the
+ * pattern.
+ * @param value true if input must contain a match to decimal mark in pattern
+ * Default is false.
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public void setDecimalPatternMatchRequired(boolean value) {
+ parseRequireDecimalPoint = value;
+ }
+
+ /**
+ * {@icu} Returns whether the input to parsing must contain a decimal mark if there
+ * is a decimal mark in the pattern.
+ * @return true if input must contain a match to decimal mark in pattern
+ * @draft ICU 54
+ * @provisional This API might change or be removed in a future release.
+ */
+ public boolean isDecimalPatternMatchRequired() {
+ return parseRequireDecimalPoint;
+ }
+
/**
* Sets the behavior of the decimal separator with integers. (The decimal separator
assertEquals("Test Currency Context", TWD_changed_expected, TWD_changed);
}
}
+
+ public void TestParseRequiredDecimalPoint() {
+
+ String[] testPattern = { "00.####", "00.0", "00" };
+
+ String value2Parse = "99";
+ double parseValue = 99;
+ DecimalFormat parser = new DecimalFormat();
+ double result;
+ boolean hasDecimalPoint;
+ for (int i = 0; i < testPattern.length; i++) {
+ parser.applyPattern(testPattern[i]);
+ hasDecimalPoint = testPattern[i].contains(".");
+
+ parser.setDecimalPatternMatchRequired(false);
+ try {
+ result = parser.parse(value2Parse).doubleValue();
+ assertEquals("wrong parsed value", parseValue, result);
+ } catch (ParseException e) {
+ this.errln("Parsing " + value2Parse + " should have succeeded with " + testPattern[i] +
+ " and isDecimalPointMatchRequired set to: " + parser.isDecimalPatternMatchRequired());
+ }
+
+ parser.setDecimalPatternMatchRequired(true);
+ try {
+ result = parser.parse(value2Parse).doubleValue();
+ if(hasDecimalPoint){
+ this.errln("Parsing " + value2Parse + " should NOT have succeeded with " + testPattern[i] +
+ " and isDecimalPointMatchRequired set to: " + parser.isDecimalPatternMatchRequired());
+ }
+ } catch (ParseException e) {
+ // OK, should fail
+ }
+ }
+
+ }
+
}