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: [email protected]
For additional commands, e-mail: [email protected]