W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2003

RE: Best way to represent fractional values?

From: Xan Gregg <xan@tibco.com>
Date: Wed, 12 Feb 2003 14:27:54 -0500
Message-ID: <339902DC0E58D411986A00B0D03D84320186AA7C@extmail.rtp.tibco.com>
To: "'Hugh Wallis'" <hugh_wallis@hyperion.com>, xmlschema-dev@w3.org
I don't think there's a better answer than Amy Lewis's on xml-dev [1].  I
prefer the first of your options, except with integer instead of decimal for
the parts.  A google search finds a similar datatype defined by something
call "ebiz" [2].
[1] http://lists.xml.org/archives/xml-dev/200302/msg00360.html
[2] http://www.posc.org/ebiz/pefxml/bdoc/dt_rational.html
-----Original Message-----
From: Hugh Wallis [mailto:hugh_wallis@hyperion.com]
Sent: Monday, February 10, 2003 12:43 PM
To: xmlschema-dev@w3.org
Subject: Best way to represent fractional values?

Because some fractional values (e.g. 1/3) cannot be exactly represented
using any of the types provided by XML Schema (due to the recurring nature
of their decimal representation) I want to define a new type that will
enable exact representation of such values.
As I see it there are two possibilities:
1) Create a complex type with a denominator and numerator, possibly
something like:

<complexType name="fraction">


          <element name="numerator" type="decimal"/>

          <element name="denominator" type="decimal"/>


2) Create a simple type as a restriction on "string", possibly something

<simpleType name="fraction">

     <restriction base="string">

          <pattern value="[0-9]+(.[0-9]+)/[0-9]+(.[0-9]+)"/>


Both of these approaches have their benefits and pitfalls of course.
Are there any "best practices" in this regard? It seems a pity that there
was no fraction type defined for us in the first place (or am I missing
something somewhere?)
Many thanks
Hugh Wallis
Received on Wednesday, 12 February 2003 14:33:28 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:59 UTC