四舍五入前完成货币字段约束检查
大家好 我正在对我的货币字段进行单元测试,我发现这个问题可以被视为一个错误。
<xforms:bind id="amount" nodeset="instance('form')/data/amount"
constraint="if(.!='') then number(.) >0 and string-length(.)<20 else ."/>
...
<fr:currency bind="amount" xxforms:maxlength="50" incremental="true">
<xforms:alert>Value should be below $ 9,999,999,999,999,999,999.99</xforms:alert>
</fr:currency>
在上述情况下我试图实现的条件是,进行最大值检查< “9999999,999999999.99”总共有 19 个字符。 (我也尝试过constraint =“if(.='')then true()else number(。)&lt;10000000000000000”也代替长度检查,但后来看到该数字检查中的一些错误切换到此字符串长度检查)
现在在这种情况下字符串长度的问题是 如果我输入“9,999,999,999,999,999.991”,则会发生以下情况 1. 进行约束检查。返回“false”为“9999999999999999.991”= 20 长度 2.货币金额四舍五入。
所以我的约束检查失败了。但是,如果我单击该字段并单击该字段之外,则约束检查返回 true,
任何人都可以建议更好的方法来执行此操作或如何解决上述问题。
HI All
i was unit testing my currency field and i found this issue that can be considered as a bug.
<xforms:bind id="amount" nodeset="instance('form')/data/amount"
constraint="if(.!='') then number(.) >0 and string-length(.)<20 else ."/>
...
<fr:currency bind="amount" xxforms:maxlength="50" incremental="true">
<xforms:alert>Value should be below $ 9,999,999,999,999,999,999.99</xforms:alert>
</fr:currency>
The condition that i am trying to achieve in the above case is, to put a max value check < "9999999,999999999.99" this has 19 characters total. (i had tried constraint="if(.='') then true() else number(.)<10000000000000000" also instead of length check, but later seeing some bug in that number check switched to this string-length check)
now the issue in this case of string length is
if i enter "9,999,999,999,999,999.991" the following happens
1. the constraint check is performed. which returns 'false' as "9999999999999999.991" = 20 length
2. the currency amount is rounded off.
so my constraint check fails. But if i click the field and click outside the field, the constraint check returns true
can anyone suggest a better way to do it or how to solve the above issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
需要注意的一些事项:
xxforms:maxlength
不适用于fr:currency
或任何其他fr:
控件数字根据其他数字进行评估,如下所示a 双精度 64 位浮点类型 。在评估数字时请考虑到这一点。基本上这意味着大量数字会被四舍五入。您在进行大量评估时遇到的问题可能不是错误,而只是数学问题。
A few things to note:
xxforms:maxlength
does not work onfr:currency
or any otherfr:
controlNumbers are evaluated against other numbers as a double-precision 64-bit floating point type. Take this into account when numbers are being evaluated. Basically what this means is large numbers get rounded. it is possible that problems you experience with large number evaluations is not a bug but rather just math.