RE: Best way to represent fractional values?

Hugh,
 
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].
 
xan
 
[1] http://lists.xml.org/archives/xml-dev/200302/msg00360.html
<http://lists.xml.org/archives/xml-dev/200302/msg00360.html> 
[2] http://www.posc.org/ebiz/pefxml/bdoc/dt_rational.html
<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">

     <sequence>

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

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

     </sequence>

</complexType>
 
2) Create a simple type as a restriction on "string", possibly something
like:
 

<simpleType name="fraction">

     <restriction base="string">

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

     </restriction>

</simpleType>
 
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