VB.Net code that I need to translate to C#:
Dim s = 27 / 15 Mod 1 //result is 0.8
Same equation in C#
var s = 27 / 15 % 1 //result is 0
Why is there a different? Is Mod different between the two?
EDIT: I am translating code from VB to C#, so I need to get the same result as the VB code in my C# code.
The division is different between the 2.
In VB.NET you get a floating point type result.
In C# this is integer division (as both operators are integers).
If you use the integer division operator in VB.NET, you will get the same result:
Dim s = 27 \ 15 Mod 1
To get the VB.NET result in C#, you need to ensure one of the division operators is a floating point type:
var s = 27 / 15.0 % 1;
var s = 27.0 / 15 % 1;
var s = 27.0 / 15.0 % 1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With