Curious behavior of Access.Application.Eval() Curious behavior of Access.Application.Eval() vba vba

Curious behavior of Access.Application.Eval()


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

Debug.Print (.575 * 100) < 57.5TrueDebug.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


That is because of different float precision.

In one case the constants get recognized as Doubles, in the other as Singles.

? math.round((.575! - Int(.575!)) * 100) 58 ? math.round((.575# - Int(.575#)) * 100) 57 


GSerg got me thinking. I'm starting to believe that Jet attempts to coerce decimal literals to the Currency type when Eval is called whereas VBA coerces decimal literals to the Double type. Case in point:

? Math.Round(.575 * 100) 57 ? Math.Round(CSng(.575) * 100) 58 ? Math.Round(CDbl(.575) * 100) 57 ? Math.Round(CCur(.575) * 100) 58 ? Eval("Round(.575 * 100)") 58 ? Eval("Round(CSng(.575) * 100)") 57 ? Eval("Round(CDbl(.575) * 100)") 57 ? Eval("Round(CCur(.575) * 100)") 58