RangeValidator最大值= 9999999999999.99与9999999999999.991 [英] RangeValidator Maximumvalue = 9999999999999.99 vs 9999999999999.991

查看:88
本文介绍了RangeValidator最大值= 9999999999999.99与9999999999999.991的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


DB中有一列,类型为十进制(15,2),UI中的数据字段具有一个RangeValidator.
以下是此RangeValidator:

Hi,
There is one column in DB with type is decimal(15,2), and its data field in UI with one RangeValidator.
Below is this RangeValidator:

<pre lang="xml"><asp:RangeValidator ID="rvDSC" runat="server" ControlToValidate="DSC" Type="Double"
    ErrorMessage="DSC should be greater than 0.01 and less than 9999999999999.99" SetFocusOnError="True"
    Display="None" MaximumValue="9999999999999.99" MinimumValue="0.01" ValidationGroup="Save"></asp:RangeValidator>




当我测试此验证器时,
1.输入9999999999999.99时通过.
2.和9999999999999.991,通过
3. 9999999999999.992,无效,
我不明白为什么rangeValidator认为此9999999999999.991有效吗?




When I test this validator, well,
1. When type 9999999999999.99 pass.
2. And 9999999999999.991, pass
3. 9999999999999.992, invalid,
I can not understand why rangeValidator think this 9999999999999.991 is valid?

推荐答案

它与浮点数的精度有关.请记住,它们在内部以二进制形式表示,并且有效数字数量有限.例如,请参见: http://www.inf.uni- konstanz.de/cgip/lehre/na_08/Lab1/4_fpns/html/Fpns.html [
It has to do with precision of floating point numbers. Remember that they are represented in binary internally with a limited number of significant figures. See for example: http://www.inf.uni-konstanz.de/cgip/lehre/na_08/Lab1/4_fpns/html/Fpns.html[^]

That''s why experienced programmers don''t do exact comparisons with floating point and don''t expect exact boundaries to work, either. If 9999999999999.991, passing is a problem, you need to rethink your representation.


这篇关于RangeValidator最大值= 9999999999999.99与9999999999999.991的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆