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 datatype

xs:double and xs:float

IEEE binary floating point, with exponents, infinities and NaN — and the rounding that makes it wrong for money.

xs:double is 64-bit IEEE 754 and xs:float is 32-bit. Both accept exponent notation and the three special values INF, -INF and NaN, spelled exactly that way.

Neither should be used for currency. 0.1 in binary floating point is not 0.1, and the discrepancy compounds. xs:decimal exists for that.

Lexical space
A decimal number with an optional e or E exponent, or one of INF, -INF, NaN.
Derives from
Primitive type
Category
Numeric types
Facets
minInclusive, maxInclusive, minExclusive, maxExclusive, pattern, enumeration, whiteSpace

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.5e3
  • -0.001
  • INF
  • -INF
  • NaN
  • 0

What does not

  • Infinity

    The spelling is INF, not Infinity.

  • nan

    NaN is case-sensitive.

  • 1,5

    The decimal separator is a point.

What catches people out

  • INF and NaN are spelled exactly that way — 'Infinity' and 'nan' both fail.
  • NaN is not equal to itself, so an enumeration containing NaN can never match.
  • Do not use it for money. xs:decimal is exact; this is not.

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:element name="v" type="xs:double"/>
</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.