我想将数字的小数位数限制为2. 例如 – 1.00有效,但1,1和1.000都无效. 这是一个类似的问题:Specify amount of decimal places of an xs:decimal in an XML schema 这就是答案: xs:simpleType name="twoPlacesDecima
例如 – 1.00有效,但1,1和1.000都无效.
这是一个类似的问题:Specify amount of decimal places of an xs:decimal in an XML schema
这就是答案:
<xs:simpleType name="twoPlacesDecimal" id="twoPlacesDecimal">
<xs:restriction base="xs:decimal">
<xs:fractionDigits fixed="true" value="2" />
</xs:restriction>
</xs:simpleType>
不幸的是,这只将小数位数限制为2,并允许数字为零或一位小数.
当我在过去做过这个时,我使用了一个正则表达式匹配器.你可以使用的正则表达式是这样的:<xsd:simpleType name="exactlyTwoAfterDecimal">
<xsd:restriction base="xsd:token">
<xsd:pattern value="^-?\d+\.\d\d$"/>
</xsd:restriction>
</xsd:simpleType>
