How to force c# binary int division to return a double?

Posted by Wayne on Stack Overflow See other posts from Stack Overflow or by Wayne
Published on 2010-03-21T04:11:46Z Indexed on 2010/03/21 4:21 UTC
Read the original article Hit count: 383

Filed under:
|
|
|
|

How to force double x = 3 / 2; to return 1.5 in x without the D suffix or casting? Is there any kind of operator overload that can be done? Or some compiler option?

Amazingly, it's not so simple to add the casting or suffix for the following reason:

Business users need to write and debug their own formulas. Presently C# is getting used like a DSL (domain specific language) in that these users aren't computer science engineers. So all they know is how to edit and create a few types of classes to hold their "business rules" which are generally just math formulas.

But they always assume that double x = 3 / 2; will return x = 1.5 however in C# that returns 1.

A. they always forget this, waste time debugging, call me for support and we fix it. B. they think it's very ugly and hurts the readability of their business rules.

As you know, DSL's need to be more like natural language.

Yes. We are planning to move to Boo and build a DSL based on it but that's down the road.

Is there a simple solution to make double x = 3 / 2; return 1.5 by something external to the class so it's invisible to the users?

Thanks! Wayne

© Stack Overflow or respective owner

How to force c# binary int division to return a double?

Posted by Wayne on Stack Overflow See other posts from Stack Overflow or by Wayne
Published on 2010-03-21T04:11:21Z Indexed on 2010/03/21 4:21 UTC
Read the original article Hit count: 383

Filed under:
|
|
|
|

How to force double x = 3 / 2; to return 1.5 in x without the D suffix or casting? Is there any kind of operator overload that can be done? Or some compiler option?

Amazingly, it's not so simple to add the casting or suffix for the following reason:

Business users need to write and debug their own formulas. Presently C# is getting used like a DSL (domain specific language) in that these users aren't computer science engineers. So all they know is how to edit and create a few types of classes to hold their "business rules" which are generally just math formulas.

But they always assume that double x = 3 / 2; will return x = 1.5 however in C# that returns 1.

A. they always forget this, waste time debugging, call me for support and we fix it. B. they think it's very ugly and hurts the readability of their business rules.

As you know, DSL's need to be more like natural language.

Yes. We are planning to move to Boo and build a DSL based on it but that's down the road.

Is there a simple solution to make double x = 3 / 2; return 1.5 by something external to the class so it's invisible to the users?

Thanks! Wayne

© Stack Overflow or respective owner

Related posts about c#

Related posts about casting