XSD datatype
xs:decimal
An exact decimal number with arbitrary precision — and no exponent notation, which is the usual reason a value is rejected.
xs:decimal represents a value exactly, with no binary floating-point rounding. It is the right type for money and for anything where 0.1 + 0.2 must equal 0.3.
Its lexical space is deliberately narrow: an optional sign, digits, an optional decimal point and more digits. No exponent, no thousands separators, no currency symbols. '1.5e3' is a valid xs:double and not a valid xs:decimal.
- Lexical space
- Optional sign, then digits with at most one decimal point. No exponent.
- Derives from
- Primitive type
- Category
- Numeric types
- Facets
- minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace, totalDigits, fractionDigits
What validates
Every literal below is put through the schema validator on each test run, against the schema at the foot of this page.
14.50-0.001+30123456789012345678901234567890.5
What does not
1.5e3Exponent notation belongs to xs:float and xs:double.
1,500.00A thousands separator is not part of the lexical space.
€14.50A currency symbol is not a number.
NaNxs:decimal has no NaN — that is a float/double concept.
(the empty string)An empty value is not a decimal.
What catches people out
- No exponent notation. This is the single most common rejection.
- Arbitrary precision: there is no maximum. A 40-digit decimal is valid, and your language's native type may not hold it.
- fractionDigits constrains the number of decimal places, and it counts the value rather than the literal — '1.50' has fractionDigits 2, '1.5' has 1.
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.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="v" type="xs:decimal"/>
</xs:schema>Related
- xs:integerA whole number of unlimited size. It derives from xs:decimal, not from a machine int — so it has no range at all.
- xs:double and xs:floatIEEE binary floating point, with exponents, infinities and NaN — and the rounding that makes it wrong for money.
- fractionDigits and totalDigitsDecimal precision limits, counted on the value rather than the literal — so trailing zeros do not count.
- minInclusive, maxInclusive and the exclusive pairRange bounds for ordered types. Inclusive includes the endpoint; exclusive does not, and mixing them up is an off-by-one you will not see.
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.