return result;
}
private String formatDecimal(String start, SchemaType sType) {
BigDecimal result = new BigDecimal(start);
XmlDecimal xmlD;
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_INCLUSIVE);
BigDecimal min = xmlD != null ? xmlD.getBigDecimalValue() : null;
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_INCLUSIVE);
BigDecimal max = xmlD != null ? xmlD.getBigDecimalValue() : null;
boolean minInclusive = true, maxInclusive = true;
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MIN_EXCLUSIVE);
if (xmlD != null) {
BigDecimal minExcl = xmlD.getBigDecimalValue();
if (min == null || min.compareTo(minExcl) < 0) {
min = minExcl;
minInclusive = false;
}
}
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_MAX_EXCLUSIVE);
if (xmlD != null) {
BigDecimal maxExcl = xmlD.getBigDecimalValue();
if (max == null || max.compareTo(maxExcl) > 0) {
max = maxExcl;
maxInclusive = false;
}
}
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_TOTAL_DIGITS);
int totalDigits = -1;
if (xmlD != null) {
totalDigits = xmlD.getBigDecimalValue().intValue();
StringBuffer sb = new StringBuffer(totalDigits);
for (int i = 0; i < totalDigits; i++) {
sb.append('9');
}
BigDecimal digitsLimit = new BigDecimal(sb.toString());
if (max != null && max.compareTo(digitsLimit) > 0) {
max = digitsLimit;
maxInclusive = true;
}
digitsLimit = digitsLimit.negate();
if (min != null && min.compareTo(digitsLimit) < 0) {
min = digitsLimit;
minInclusive = true;
}
}
int sigMin = min == null ? 1 : result.compareTo(min);
int sigMax = max == null ? -1 : result.compareTo(max);
boolean minOk = sigMin > 0 || sigMin == 0 && minInclusive;
boolean maxOk = sigMax < 0 || sigMax == 0 && maxInclusive;
// Compute the minimum increment
xmlD = (XmlDecimal) sType.getFacet(SchemaType.FACET_FRACTION_DIGITS);
int fractionDigits = -1;
BigDecimal increment;
if (xmlD == null) {
increment = new BigDecimal(1);
} else {
fractionDigits = xmlD.getBigDecimalValue().intValue();
if (fractionDigits > 0) {
StringBuffer sb = new StringBuffer("0.");
for (int i = 1; i < fractionDigits; i++) {
sb.append('0');
}