Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Int32.TryParse and F#+ tryParse give different results #541

Open
@abelbraaksma

Description

@abelbraaksma

Description

Basically (tested with culture onen-US).

> let value: int option = tryParse "123,45";;val value: int option = Some 12345> Int32.TryParse "123,45";;val it: bool * int = (false, 0)

In other words, integers cannot have thousand-separators withInt32.TryParse, but can withtryParse.

Conversely, it doesn't allow decimals, which is good:

> let value: int option = tryParse "123.45";;val value: int option = None> Int32.TryParse "123.45";;val it: bool * int = (false, 0)

Likewise there's a similar difference withe-notation:

> let value: int option = tryParse "12345e4";;val value: int option = Some 123450000> Int32.TryParse "12345e4";;val it: bool * int = (false, 0)

Repro steps

See above.

Expected behavior

From the description of the method, you'd expect the same behavior as the .NET functions, but they allow certain illegal values, or at least ambiguous, considering how .NET parses numbers.

Actual behavior

See above. This is caused byNumberStyles.Any, which is not used byInt32.TryParse orDecimal.TryParse. These useNumberStyles.Integer andNumberStyles.Decimal respectively (see source of .NET), which limit the allowed range.

Known workarounds

Create your own types or callInt32.TryParse directly, or create your own helper function.

Related information

Most recent F#+ and tested with .NET 6, but assuming it is the same on .NET 7.

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


      [8]ページ先頭

      ©2009-2026 Movatter.jp