使用Spring.net进行xVal验证(xVal validation with Spring.net)
我已经开始使用xVal作为ASP.Net MVC应用程序的验证框架。 我使用Spring.Net IoC容器将应用程序保存在一起。
我按照Steve Sanderson博客上的说明进行操作,以使服务器端验证工作正常。 但是当我尝试让客户端工作时,我得到以下运行时异常:
Spring.Objects.Factory.NoSuchObjectDefinitionException was unhandled by user code
Message =“没有定义名为'Scripts'的对象:找不到对象[Scripts]的定义”
我认为这是因为Site.Masterpage中包含以下代码:
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>"></script> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.validate.js")%>"></script> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/xVal.jquery.validate.js")%>"></script>
哪个尝试解决〜/ Scripts /使用Spring。
如何让Spring处理这个问题(即配置XML中的内容),或者我在Site.Master中更改了什么,这样就不会发生这种情况?
I have started to play with xVal as my validation framework for an ASP.Net MVC application. I use the Spring.Net IoC container to hold the app together.
I have followed the instructions on Steve Sanderson's blog to get server side validation working fine. But when I try to get client side working, I get the following runtime exception:
Spring.Objects.Factory.NoSuchObjectDefinitionException was unhandled by user code
Message="No object named 'Scripts' is defined : Cannot find definition for object [Scripts]"
I presume this is because the Site.Masterpage has the following code in it:
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.2.6.js")%>"></script> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery.validate.js")%>"></script> <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/xVal.jquery.validate.js")%>"></script>
Which is trying to resolve ~/Scripts/ using Spring.
How do I get either Spring to cope with this (i.e. what goes into the config XML), or what do I change in Site.Master so this does not happen?
原文:https://stackoverflow.com/questions/827091
最满意答案
两者之间确实没有区别,但编译器在涉及到浮点计算时习惯于采取一些自由度。 例如,编译器可以自由使用更高的精度来计算中间结果,但更高的结果仍然意味着不同,因此结果可能会有所不同。
有些编译器提供的开关总是会降低额外的精度,并将所有中间结果转换为规定的浮点数(比如64位双精度数)。 然而,这会使代码变慢。
在具体的数字
45.33
不能完全用浮点值表示(这是一个二进制表示的周期数,它将需要无限的位数)。 当乘以100
这个值可能是你没有得到一个整数,但是非常接近的东西(正好在下面或正上方)。
int
转换或铸造是使用截断和非常接近4533
但以下将成为4532
,当上述将成为4533
; 即使这种差异非常小,比如说1E-300
。为避免出现问题,请务必考虑数字精度问题。 如果你正在做一个依赖于浮点数的确切值的计算,那么你正在使用错误的工具。
There is indeed no difference between the two, but compilers are used to take some freedom when it comes down to floating point computations. For example compilers are free to use higher precision for intermediate results of computations but higher still means different so the results may vary.
Some compilers provide switches to always drop extra precision and convert all intermediate results to the prescribed floating point numbers (say 64bit double-precision numbers). This will make the code slower, however.
In the specific the number
45.33
cannot be represented exactly with a floating point value (it's a periodic number when expressed in binary and it would require an infinite number of bits). When multiplying by100
this value may be you don't get an integer, but something very close (just below or just above).
int
conversion or cast is performed using truncation and something very close to4533
but below will become4532
, when above will become4533
; even if the difference is incredibly tiny, say1E-300
.To avoid having problems be sure to account for numeric accuracy problems. If you are doing a computation that depends on exact values of floating point numbers then you're using the wrong tool.
相关问答
更多-
如何在Java中将一个double转换为int,将其舍入?(How to cast a double to an int in Java by rounding it down?)[2021-12-21]
转换为int隐式删除任何小数。 不需要调用Math.floor()(假定正数) (int)简单的typecast,例如: System.out.println((int)(99.9999)); // Prints 99 话虽如此,它确实与Math.floor行为不同,后者向负无穷大转变(@Chris Wong) Casting to an int implicitly drops any decimal. No need to call Math.floor() (assuming positive nu ... -
您可以使用std::stringstream 。 #include
#include #include using namespace std; int main(void) { double var = 1.0000001; cout << setprecision(10)<< var << endl; stringstream ss; ss << setprecision(10) << var; st ... -
错误:可能损失精度(Error: Possible Loss Of Precision)[2022-06-02]
您的方法签名表明您在实际返回double时返回int。 您可以通过将签名更改为: static double compoundBalance(double db, double dbTwo, double dbThree) { 当你打算返回6.9时,这个错误就是阻止你返回类似6的东西。 如果您确实需要此行为,则可以将返回值强制转换为int,而不是更改签名。 static int compoundBalance(double db, double dbTwo, double dbThree) { if( ... -
两者之间确实没有区别,但编译器在涉及到浮点计算时习惯于采取一些自由度。 例如,编译器可以自由使用更高的精度来计算中间结果,但更高的结果仍然意味着不同,因此结果可能会有所不同。 有些编译器提供的开关总是会降低额外的精度,并将所有中间结果转换为规定的浮点数(比如64位双精度数)。 然而,这会使代码变慢。 在具体的数字45.33不能完全用浮点值表示(这是一个二进制表示的周期数,它将需要无限的位数)。 当乘以100这个值可能是你没有得到一个整数,但是非常接近的东西(正好在下面或正上方)。 int转换或铸造是使用截断 ...
-
精度损失(Loss of precision)[2022-08-20]
4.35不能精确地表示为浮点数,因为.35不是2的(负)幂。因此,有一些方法可以这样或那样。 当你乘以100时,可能还会有舍入。如果得到的数字小于435,则转换为int将占用它的最低值,即434。 如果你想舍入到NEAREST整数,你可以在结果中加0.5,然后转换为int。 尽管Java具有内置的舍入实现,但这是舍入数字的最常用方法。 double f = 4.35; int n = (int) (100 * f + 0.5); 4.35 cannot be represented exactly a ... -
将long或BigInteger乘以double而不会损失精度(Multiply long or BigInteger by double without loss of precision)[2022-05-22]
您想使用BigDecimal以保持精度。 BigInteger myBI = new BigInteger("99999999999999999"); Double d = 0.123; BigDecimal bd = new BigDecimal(myBI); BigDecimal result = bd.multiply(BigDecimal.valueOf(d)); Using BigDecimal indeed works. You still have to be carefull about ... -
奇怪的双舍入问题(Strange double rounding issue)[2023-02-11]
链接中的代码与最初在此处发布的代码之间存在一个小但重要的区别, meaning += Math.random() + 1; // link 与 meaning += (int)Math.random() + 1; // StackOverflow 如果这里发布的代码打印出除42之外的任何内容,那么这是一个严重的错误。 这里, Math.random()的结果显式地转换为int , 必须得到0,然后添加1,得到1,然后将其添加到meaning 。 然而,在将Math.random()的结果添加到1 ... -
我知道给定字符串的类型但我不能使用strtoll,因为数字是用科学记数法给出的。 您只需要调用一次,使用结果指针来检测该数字是否为xxxeyyy形式,并再次调用strtoll来解析指数。 在我看来,比通过浮点更简单。 我知道这个数字足够长,可以用双精度正确表示。 不,您不知道,因为您的示例输入是“123456789012345678”,这在IEEE 754双精度中无法表示。 我可以使用长双,但这不会解决问题。 实际上,如果你的编译器将long double映射到“具有64位有效数字的80位扩展精度”,它将解 ...
-
当你使用Int()它会强制你的数字被截断,总是向零逼近。 因此,6.9999变成了6而不是7,因为它接近零。 如果你首先使用round()它应该有所帮助: var steps: Int { return Int(round((max - min) / step) + 1.0) } When you use Int() it forces truncation of your number, which always rounds towards zero. So, 6.9999 becomes 6 ...
-
精度损失?(Loss of precision?)[2023-01-25]
您展示的任何替代方案都没有给出任何精度损失[至少不是编译器执行标准所说的应该做的事情]。 这是所有二元运算符,其中一个操作数是double ,另一方自动升级为double [并且通常,当两个操作数大小不同时,它们被提升为更大的操作数]。 特别是,始终精确地表示整数值[低于尾数的位数]。 [显然,我们不知道calc对你的输入做了什么 - 这可能是任何和各种错误的根源,但我假设你实际上在询问你建议的情况下3.0/8.0是否总是0.375 - 当然3/8会导致零,因为两边都是整数] 编辑以响应正在编辑的原始问题: ...