Skip to content

VB -> C#: VB float division (/) is converted as an integer division #1160

Description

@jrfstr

VB.Net input code

Dim TotalRead as UInteger
Dim ContentLenght as UInteger  (It is supposed that TotalRead < ContentLength)
Dim porcentage As Integer = Convert.ToInt32((TotalRead / ContentLenght) * 100.0)

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

uint TotalRead;
uint ContentLenght;
int porcentage = Convert.ToInt32(TotalRead / ContentLenght * 100.0d); 

Here TotalRead / ContentLenght is an integer and porcentaje only takes two values: 0 and 100

Expected output

int porcentage = Convert.ToInt32((double)TotalRead / (double)ContentLenght * 100.0d);

Details

  • Product in use: Code Converter (VB - C#) (VS extension)
  • Version in use: 9.2.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions