Skip to content

(int) cast of double rounds the double instead of truncating it #130

@Crown0815

Description

@Crown0815

In C# the call

var x = (int) 3.6;

produces x = 3.

The same call in ExpressionEvaluator produces x = 4 instead.

This is due to the usage of

...
return Convert.ChangeType(value, conversionType);

in line 4150, which for the given example resolves to Convert.ChangeType(3.6, typeof(int)) which indeed resolves to 4.

I understand if this is a design decision, but it might be a source of issues. We use ExpressionEvaluator to simulate C# code, which means for us, it is non-expected behavior.

For our intents and purposes it would be great to have an option to turn integer casting from round to truncate e.g. with

evaluator.OptionTruncateOnIntegerCast = true;

This would preserve current behavior but enable a more correct simulation of C# behavior.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions