-
Notifications
You must be signed in to change notification settings - Fork 222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VB -> C#: VB float division (/) is converted as an integer division #1160
Comments
Sorry I can't reproduce the issue This might be some difficulty with the dot net version for example. What project type? |
The dot net version is .NET 9.0. The project type is a class library (in VB). In https://icsharpcode.github.io/CodeConverter/ I can't reproduce the issue. Things gone right there. |
Sorry, that was not the code. Try this in the link: Public Class VisualBasicClass
public sub x()
Dim TotalRead as long
Dim ContentLenght as long? '(It is supposed that TotalRead < ContentLength)
Dim porcentage As Integer = Convert.ToInt32((TotalRead / ContentLenght) * 100.0)
End Sub
End Class The output in c# is using System;
public partial class VisualBasicClass
{
public void x()
{
var TotalRead = default(long);
var ContentLenght = default(long?); // (It is supposed that TotalRead < ContentLength)
int porcentage = Convert.ToInt32(TotalRead / ContentLenght * 100.0d);
}
} |
Yep that repros. It's an issue specifically with the logic around nullable not working correctly with logic around casting |
…nversion - fixes #1160 Changes the results of a few other tests so likely needs refinement
I made a start on fixing up the issue, but there are a couple of situations in other tests that need thinking about before it could be merged |
Thanks very much for your this project! |
Consider the underlying type if the conversion is a nullable value conversion - fixes #1160
VB.Net input code
In VB TotalRead / ContentLenght is a float number. I guess the operands are converted to float before perform the division. Percentage can take all values between 0 and 100.
Erroneous output
Here TotalRead / ContentLenght is an integer and porcentaje only takes two values: 0 and 100
Expected output
Details
The text was updated successfully, but these errors were encountered: