Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Int32.TryParse and F#+ tryParse give different results

Aperta
#541 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
fsharp
Ambito
backend

Direzione di ricerca

Inizia dal punto di ingresso tryParse di F#+ e riproduci i casi en-US segnalati, confrontandoli con .NET Int32.TryParse e Decimal.TryParse. Verifica il comportamento di NumberStyles.Any descritto nell’issue; il lavoro è completato quando tryParse segue il comportamento di analisi .NET corrispondente, mantenendo il rifiuto dei decimali indicato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug F#+ v2.0
Description

Basically (tested with culture on en-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 with Int32.TryParse, but can with tryParse.

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 with e-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 by NumberStyles.Any, which is not used by Int32.TryParse or Decimal.TryParse. These use NumberStyles.Integer and NumberStyles.Decimal respectively (see source of .NET), which limit the allowed range.

Known workarounds

Create your own types or call Int32.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.

Lingua principale
F#
Stelle
941
Fork
106
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fsprojects/FSharpPlus

Tutte le issue di fsprojects/FSharpPlus

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.