|
Il presente articolo è stato tradotto automaticamente. Passare il puntatore sulle frasi nell'articolo per visualizzare il testo originale. Ulteriori informazioni.
|
Traduzione
Originale
|
Metodo Decimal.Parse (String, IFormatProvider)
Spazio dei nomi: System
Assembly: mscorlib (in mscorlib.dll)
Parametri
- s
- Tipo: System.String
Rappresentazione di stringa del numero da convertire.
- provider
- Tipo: System.IFormatProvider
Oggetto IFormatProvider che fornisce informazioni di analisi specifiche delle impostazioni cultura relative a s.
Valore restituito
Tipo: System.Decimal| Eccezione | Condizione |
|---|---|
| ArgumentNullException | |
| FormatException | |
| OverflowException |
protected void OkToDecimal_Click(object sender, EventArgs e) { string locale; decimal number; CultureInfo culture; // Return if string is empty if (String.IsNullOrEmpty(this.inputNumber.Text)) return; // Get locale of web request to determine possible format of number if (Request.UserLanguages.Length == 0) return; locale = Request.UserLanguages[0]; if (String.IsNullOrEmpty(locale)) return; // Instantiate CultureInfo object for the user's locale culture = new CultureInfo(locale); // Convert user input from a string to a number try { number = Decimal.Parse(this.inputNumber.Text, culture.NumberFormat); } catch (FormatException) { return; } catch (Exception) { return; } // Output number to label on web form this.outputNumber.Text = "Number is " + number.ToString(); }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (ruoli di base del server non supportati), Windows Server 2008 R2 (ruoli di base del server supportati con SP1 o versione successiva, Itanium non supportato)
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.