Formatting xsd:decimal Values

The formatting of xsd:decimal values differs from xsd:double values, and is much simpler. This because the decimal type may not use exponents.

Overview of Options

totalDigits This limits the number of digits in the number. Leading zeros in the integer part and trailing zeros in the fraction part do not count (as with the XML Schema totalDigits facet).
fractionDigits This limits the number of fraction digits in the number. Trailing zeros in the fraction part do not count (as with the XML Schema fractionDigits facet)
integerMaxDigits Not used with xsd:decimal.

integerMinDigits

fractionMinDigits

These specify the minimum number of digits to display in the integer and fraction parts. For the integer part, leading zeros may be added. For the fraction part, trailing zeros may be added.
signPresent Formatting option to force display of positive signs.
pointPresent Force the display of the decimal point. Note that specifying fractionMinDigits > 0 also will force the display of the decimal point.

Rounding

Fractional digits are rounded off to meet the given totalDigits and fractionDigits settings. In some cases, rounding causes carryover and adds an additional integer digit, which may then violate the totalDigits setting. See the discussion of validation below.

value totalDigits setting fractionDigits setting result
456 2 any violates totalDigits
999.999 3 any violates totalDigits (after rounding, 4 integer digits are needed)
999.99 4 any “1000”

Formatting Ouput

After rounding, leading and trailing zeros are added, as needed, to meet the integerMinDigits and fractionMinDigits parameters. Note that integerMinDigits and fractionMinDigits are not limited by totalDigits or fractionDigits (since these add leading/trailing zeros).

If the integer portion is zero, integerMinDigits controls whether the zero is displayed. If integerMinDigits = 0 was specified, it is not displayed. In all other cases, the zero will be displayed.

Note that fractionMinDigits, in particular, may produce strange looking results, as it may make a number appear to be more precise when digits have been rounded away. For example, we may round 12345.67 to 12346 due to a totalDigits setting of 5, but format this as “12346.00” due to a fractionMinDigits setting of 2.

Relationship to totalDigits/fractionDigits Facets

If the value has a totalDigits or fractionDigits facet, the facet will be used instead of any value specified in the configuration file.

Relationship to Validation

The only possible validation violation is for a totalDigits setting to be violated by a value such that |value| 10totalDigits . For all other values, rounding is used to avoid validation violations.

If the totalDigits setting being applied comes from a totalDigits facet and -lax is not in use, an error will occur. In all other cases, the violation of the totalDigits setting will be ignored. However, the totalDigits setting will still serve to limit the number of fractional digits – there will be 0 fractional digits (since the integer digits will consume all of the available digits, and more).

Default Behavior

The default behavior (when no configuration options or facets are present) is to format the value using as many digits as needed for an exact representation.

Example

integerMinDigits fractionMinDigits signPresent value result
4 2 true 12 "+0012.00"