Access.Application.Eval的)好奇的行为( [英] Curious behavior of Access.Application.Eval()

查看:159
本文介绍了Access.Application.Eval的)好奇的行为(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解释为什么 Access.Application.Eval()(通常简称为的eval())产生不同的结果不仅仅是评估原来EX pression在这种情况下:

  Debug.Print圆(0.575 * 100)
 57
Debug.Print的eval(圆(0.575 * 100))
 58
 


编辑:为了解决GSerg的回答,下面仍返回不同的结果:

  Debug.Print的eval(圆(CSng函数(0.575)* 100))
 57
Debug.Print回合(CSng函数(0.575)* 100)
 58
 

解决方案

这乘返回的eval()根据不同的产品,但我不明白为什么。

  Debug.Print(0.575 * 100)LT; 57.5
真正

Debug.Print的eval((575 * 100)= 57.5)
-1
 

在第一种情况下,该产品是小于57.5,所以圆()将轮它下降到57。

在第二种情况下,该产品是等于57.5,所以圆()将应用其标准的舍入到连的方法,得到58

修改:你们都是正确的的eval()强制转换字面值到不同的数据类型

 ?类型名(0.575)
双

?的eval(类型名(0.575))
十进制

?轮(CDEC(0.575)* 100)
 58
 

Explain why Access.Application.Eval() (commonly abbreviated as Eval()) produces a different result than just evaluating the original expression in this case:

Debug.Print Round(.575 * 100)
 57 
Debug.Print Eval("Round(.575 * 100)")
 58 


EDIT: To address GSerg's answer, the following still returns different results:

Debug.Print Eval("Round(CSng(.575) * 100)")
 57 
Debug.Print Round(CSng(.575) * 100)
 58 

解决方案

That multiplication returns a different product under Eval(), but I don't understand why.

Debug.Print (.575 * 100) < 57.5
True

Debug.Print Eval("(.575 * 100) = 57.5")
-1

In the first case, the product is less than 57.5, so Round() will round it down to 57.

In the second case, the product is equal to 57.5, so Round() will apply its standard "round to even" approach to yield 58.

Edit: You all are right that Eval() coerces the literal value to a different data type.

? TypeName(.575)
Double

? Eval("TypeName(.575)")
Decimal

? Round(CDec(.575) * 100)
 58

这篇关于Access.Application.Eval的)好奇的行为(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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