Skip to content

C# -> VB: Math.Truncate is not added when converting Double(/Decimal) to Integer #1021

Done

Description

@tats-u

Input code

using System;

public partial class A
{
    public static void Main()
    {
        double foo = 0.6d;
        int bar = (int)foo;
        int baz = (int)Math.Ceiling(foo);
        Console.WriteLine(bar);
        Console.WriteLine(baz);
    }
}

https://sharplab.io/#v2:C4LgTgrgdgNAJiA1AHwAICYCMBYAUH1AZgAIAHAQzGAEtyAbYjYgQTwG89ivH11PuOubsOJwA9hABGdAKbEAZmLHEAvMQAMAOgBscANz8RxalGDFJlVcQAUJ4AEpFYg0KPHT58gC8rt0/YBZcmAAC00AYRlqOhMAc2snexc3RkwATmsLMCTDEVR0zO8c1y4AXzxSoA==

Produces:

0
1

Erroneous output

Imports System

Public Partial Class A
    Public Shared Sub Main()
        Dim foo = 0.6R
        Dim bar As Integer = foo
        Dim baz As Integer = Math.Ceiling(foo)
        Console.WriteLine(bar)
        Console.WriteLine(baz)
    End Sub
End Class

https://sharplab.io/#v2:DYLgbgRgNALiBOBXAdlAJiA1AHwJIFsAHAe3hgGcACAZQE9yYBTfAWACh2AFRCYASwDGlTgEMyfEcEoBhYCPJUAgu0qrhPfkOoALMYzQ0elALIi+yABQBKFWrsARPvkoAzYsUoBeSgAYAdABsAEq2dqqOzhBilIpUuMhMAOaM8F6u7qFhEZRRAF4xcQmMyanepjDaftKMfPzIiRZuxDZsYWrSxMjkxMCMfgDq8HxMADLmjBZR8C1tqh1dPX2Dw4xjyBN5M2oAosgG1Dzsuway8uTsQA=

Produces:

1
1

Expected output

Imports System

Public Partial Class A
    Public Shared Sub Main()
        Dim foo = 0.6R
        Dim bar As Integer = Math.Truncate(foo)
        Dim baz As Integer = Math.Ceiling(foo)
        Console.WriteLine(bar)
        Console.WriteLine(baz)
    End Sub
End Class

https://sharplab.io/#v2:DYLgbgRgNALiBOBXAdlAJiA1AHwJIFsAHAe3hgGcACAZQE9yYBTfAWACh2AFRCYASwDGlTgEMyfEcEoBhYCPJUAgu0qrhPfkOoALMYzQ0elALIi+yABQBKFWrsARPvkoAzYsUoBeSgAYAdABsAEq2dqqOzhBilIpUuMhMAOaM8F4mIjDafgAqSMgCGYwWbsQ2bGFqEZRRAF4xcQmMyaneppl+0ox8/MiJxe5lFarSxMjkxMCMfgDq8HxMADLmRVHwg0MjYxNTs/OMS8grIjXrqgCiyAbUPOwXBrLy5EA

Produces:

0
1

Details

Reverse conversion of #1020

Activity

  1. added
    C# -> VB
    on Jul 2, 2023
  2. added
    output logic error
    on Jul 2, 2023
  3. added
    Good for coding agent
    on Apr 19, 2026
  4. added a commit that references this issue on Nov 24, 2026
    d8bc1e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C# -> VBGood for coding agentoutput logic error

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions