Nick,
this is a pure Java question, nothing to do with XMLBeans really.
You are using the BigDecimal(double) constructor; you probably
want to use the BigDecimal(String) constructor.
The phrase to keep in mind is: decimal representation of binary
floating point value.
See 
http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(double).
- Wing Yew

-----Original Message-----
From: NickDeGraeve [mailto:nick.degra...@pandora.be] 
Sent: Friday, January 15, 2010 6:11 AM
To: user@xmlbeans.apache.org
Subject: Decimal rounding issue


I have an XSD from which I generated my XmlBeans classes.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:me="http://my.url"; 
        targetNamespace="http://my.url"; >
        <xs:element name="MyElement">
                <xs:complexType>                        
                        <xs:attribute name="myAttribute" type="me:ValueType" />
                </xs:complexType>
        </xs:element>
        <xs:simpleType name="ValueType">
                <xs:restriction base="xs:decimal" >
                        <xs:fractionDigits value="2" />
                </xs:restriction>
        </xs:simpleType>
</xs:schema>

Wheh I run this JUnit test case:

public class XmlBeansTestCase extends TestCase {

   public void test() {
      MyElementDocument document = MyElementDocument.Factory.newInstance();
      MyElement myElement = document.addNewMyElement();
      myElement.setMyAttribute(new BigDecimal(12.65));
      System.out.println(document);
      XmlOptions options = new XmlOptions();
      Collection errors = new LinkedList();
      options.setErrorListener(errors);
      boolean valid = document.validate(options);
      System.out.println(errors);
      assertTrue(valid);
   }
}

the test fails and I get this output:

<MyElement
my:myAttribute="12.6500000000000003552713678800500929355621337890625"
xmlns="http://my.url"; xmlns:my="http://my.url"/>
[error: cvc-fractionDigits-valid: Decimal fractional digits (49) of value
'12.6500000000000003552713678800500929355621337890625' does not match
fractionDigits facet (2) for ValueType in namespace http://my.url]

Why does it come out like that and not as "12.65"? 
How can I get it right?
-- 
View this message in context: 
http://old.nabble.com/Decimal-rounding-issue-tp27176674p27176674.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: user-h...@xmlbeans.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@xmlbeans.apache.org
For additional commands, e-mail: user-h...@xmlbeans.apache.org

Reply via email to