Skip to main content
XMLDir

Search 261 pages — tools, formats, elements, namespaces, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

XSD facet

fractionDigits and totalDigits

Decimal precision limits, counted on the value rather than the literal — so trailing zeros do not count.

fractionDigits caps the number of digits after the decimal point; totalDigits caps the number of significant digits overall. Both are measured on the value, not on how it was written.

That means '1.50' has one fraction digit, because the trailing zero is not significant. A schema with fractionDigits 1 accepts it.

Lexical space
A non-negative integer.
Derives from
Primitive type
Category
Constraining facets

What validates

Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.

  • 1.5

What does not

  • 1.555

    More fraction digits than the example schema allows.

What catches people out

  • Counted on the value: '1.50' has one fraction digit, not two.
  • fractionDigits 0 is how xs:integer is derived from xs:decimal.
  • They apply only to decimal-derived types, not to float or double.

The schema used

This is the exact schema the literals above are validated against. Paste it into the validator with one of them to see the result yourself.

schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="t"><xs:restriction base="xs:decimal"><xs:fractionDigits value="2"/><xs:totalDigits value="6"/></xs:restriction></xs:simpleType>
  <xs:element name="v" type="t"/>
</xs:schema>

Open the XSD validator

Related

All 29 datatypes and facets

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.