加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

需要使用XML架构的多个小数位小数

发布时间:2020-12-16 23:02:57 所属栏目:百科 来源:网络整理
导读:我想将数字的小数位数限制为2. 例如 – 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:restrictio
我想将数字的小数位数限制为2.

例如 – 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+.dd$"/>
    </xsd:restriction>
</xsd:simpleType>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读