Skip to content

Exception with "N0" format string and integer value of 0 #118

Closed
@nfbot

Description

@nfbot

From nf-interpreter created by MikroBusNet : nanoframework/nf-interpreter#285

The following code will throw a 'System.ArgumentOutOfRangeException' in mscorlib.dll :

private static uint myVar = 0;

public static void Main()
{
    Debug.Print("myVar = " + myVar.ToString("N0"));
}

If myVar is 0 and precision is 0 for the 'N' format string, then the FormatNative() method is returning an empty string, which will raise the exception in the InsertGroupSeparators() method (in Number.cs), since original.Length is 0 :

int digitsStartPos = (original[0] == '-') ? 1 : 0;

We can see the same behaviour for all integral types except long and ulong.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions