Double.Parse Méthode
Définition
Convertit la représentation sous forme de chaîne d'un nombre en nombre à virgule flottante double précision équivalent.Converts the string representation of a number to its double-precision floating-point number equivalent.
Surcharges
Parse(String, NumberStyles, IFormatProvider) |
Convertit la représentation sous forme de chaîne d'un nombre dans un style et un format propre à la culture spécifiés en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. |
Parse(String, IFormatProvider) |
Convertit la représentation sous forme de chaîne d'un nombre dans un format propre à la culture spécifié en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent. |
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) |
Convertit une étendue de caractères contenant la représentation sous forme de chaîne d'un nombre dans un style et un format propre à la culture spécifiés en nombre à virgule flottante double précision équivalent.Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. |
Parse(String) |
Convertit la représentation sous forme de chaîne d'un nombre en nombre à virgule flottante double précision équivalent.Converts the string representation of a number to its double-precision floating-point number equivalent. |
Parse(String, NumberStyles) |
Convertit la représentation sous forme de chaîne d'un nombre dans un style spécifié en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified style to its double-precision floating-point number equivalent. |
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Parse(String, NumberStyles, IFormatProvider)
Convertit la représentation sous forme de chaîne d'un nombre dans un style et un format propre à la culture spécifiés en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent.
public:
static double Parse(System::String ^ s, System::Globalization::NumberStyles style, IFormatProvider ^ provider);
public static double Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
public static double Parse (string s, System.Globalization.NumberStyles style, IFormatProvider? provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> double
Public Shared Function Parse (s As String, style As NumberStyles, provider As IFormatProvider) As Double
Paramètres
- s
- String
Chaîne contenant un nombre à convertir.A string that contains a number to convert.
- style
- NumberStyles
Combinaison d'opérations de bit des valeurs d'énumération qui indiquent les éléments de style qui peuvent être présents dans s
.A bitwise combination of enumeration values that indicate the style elements that can be present in s
. Une valeur typique à spécifier est Float combinée avec AllowThousands.A typical value to specify is Float combined with AllowThousands.
- provider
- IFormatProvider
Objet qui fournit des informations de mise en forme propres à la culture sur s
.An object that supplies culture-specific formatting information about s
.
Retours
Nombre à virgule flottante double précision équivalant à la valeur numérique ou au symbole spécifié dans s
.A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s
.
Exceptions
s
a la valeur null
.s
is null
.
s
ne représente pas une valeur numérique.s
does not represent a numeric value.
style
n’est pas une valeur NumberStyles.style
is not a NumberStyles value.
-ou--or-
style
est la valeur AllowHexSpecifier.style
is the AllowHexSpecifier value.
.NET Framework et .NET Core 2.2 et versions antérieures uniquement : s
représente un nombre inférieur à MinValue ou supérieur à MaxValue..NET Framework and .NET Core 2.2 and earlier versions only: s
represents a number that is less than MinValue or greater than MaxValue.
Exemples
L’exemple suivant illustre l’utilisation de la Parse(String, NumberStyles, IFormatProvider) méthode pour assigner plusieurs représentations sous forme de chaîne de valeurs de température à un Temperature
objet.The following example illustrates the use of the Parse(String, NumberStyles, IFormatProvider) method to assign several string representations of temperature values to a Temperature
object.
using System;
using System.Globalization;
public class Temperature
{
// Parses the temperature from a string. Temperature scale is
// indicated by 'F (for Fahrenheit) or 'C (for Celsius) at the end
// of the string.
public static Temperature Parse(string s, NumberStyles styles,
IFormatProvider provider)
{
Temperature temp = new Temperature();
if (s.TrimEnd(null).EndsWith("'F"))
{
temp.Value = Double.Parse(s.Remove(s.LastIndexOf((char)39), 2),
styles, provider);
}
else
{
if (s.TrimEnd(null).EndsWith("'C"))
temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf((char)39), 2),
styles, provider);
else
temp.Value = Double.Parse(s, styles, provider);
}
return temp;
}
// Declare private constructor so Temperature so only Parse method can
// create a new instance
private Temperature() {}
protected double m_value;
public double Value
{
get { return m_value; }
private set { m_value = value; }
}
public double Celsius
{
get { return (m_value - 32) / 1.8; }
private set { m_value = value * 1.8 + 32; }
}
public double Fahrenheit
{
get {return m_value; }
}
}
public class TestTemperature
{
public static void Main()
{
string value;
NumberStyles styles;
IFormatProvider provider;
Temperature temp;
value = "25,3'C";
styles = NumberStyles.Float;
provider = CultureInfo.CreateSpecificCulture("fr-FR");
temp = Temperature.Parse(value, styles, provider);
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.",
temp.Fahrenheit, temp.Celsius);
value = " (40) 'C";
styles = NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite
| NumberStyles.AllowParentheses;
provider = NumberFormatInfo.InvariantInfo;
temp = Temperature.Parse(value, styles, provider);
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.",
temp.Fahrenheit, temp.Celsius);
value = "5,778E03'C"; // Approximate surface temperature of the Sun
styles = NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands |
NumberStyles.AllowExponent;
provider = CultureInfo.CreateSpecificCulture("en-GB");
temp = Temperature.Parse(value, styles, provider);
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.",
temp.Fahrenheit.ToString("N"), temp.Celsius.ToString("N"));
}
}
Imports System.Globalization
Public Class Temperature
' Parses the temperature from a string. Temperature scale is
' indicated by 'F (for Fahrenheit) or 'C (for Celsius) at the end
' of the string.
Public Shared Function Parse(s As String, styles As NumberStyles, _
provider As IFormatProvider) As Temperature
Dim temp As New Temperature()
If s.TrimEnd(Nothing).EndsWith("'F") Then
temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), _
styles, provider)
Else
If s.TrimEnd(Nothing).EndsWith("'C") Then
temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2), _
styles, provider)
Else
temp.Value = Double.Parse(s, styles, provider)
End If
End If
Return temp
End Function
' Declare private constructor so Temperature so only Parse method can
' create a new instance
Private Sub New
End Sub
Protected m_value As Double
Public Property Value() As Double
Get
Return m_value
End Get
Private Set
m_value = Value
End Set
End Property
Public Property Celsius() As Double
Get
Return (m_value - 32) / 1.8
End Get
Private Set
m_value = Value * 1.8 + 32
End Set
End Property
Public ReadOnly Property Fahrenheit() As Double
Get
Return m_Value
End Get
End Property
End Class
Public Module TestTemperature
Public Sub Main
Dim value As String
Dim styles As NumberStyles
Dim provider As IFormatProvider
Dim temp As Temperature
value = "25,3'C"
styles = NumberStyles.Float
provider = CultureInfo.CreateSpecificCulture("fr-FR")
temp = Temperature.Parse(value, styles, provider)
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.", _
temp.Fahrenheit, temp.Celsius)
value = " (40) 'C"
styles = NumberStyles.AllowLeadingWhite Or NumberStyles.AllowTrailingWhite _
Or NumberStyles.AllowParentheses
provider = NumberFormatInfo.InvariantInfo
temp = Temperature.Parse(value, styles, provider)
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.", _
temp.Fahrenheit, temp.Celsius)
value = "5,778E03'C" ' Approximate surface temperature of the Sun
styles = NumberStyles.AllowDecimalPoint Or NumberStyles.AllowThousands Or _
NumberStyles.AllowExponent
provider = CultureInfo.CreateSpecificCulture("en-GB")
temp = Temperature.Parse(value, styles, provider)
Console.WriteLine("{0} degrees Fahrenheit equals {1} degrees Celsius.", _
temp.Fahrenheit.ToString("N"), temp.Celsius.ToString("N"))
End Sub
End Module
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Le style
paramètre définit les éléments de style (tels que les espaces blancs, les séparateurs de milliers et les symboles monétaires) qui sont autorisés dans le s
paramètre pour que l’opération d’analyse aboutisse.The style
parameter defines the style elements (such as white space, thousands separators, and currency symbols) that are allowed in the s
parameter for the parse operation to succeed. Il doit s’agir d’une combinaison de bits indicateurs de l' NumberStyles énumération.It must be a combination of bit flags from the NumberStyles enumeration. Les membres suivants ne NumberStyles sont pas pris en charge :The following NumberStyles members are not supported:
Le s
paramètre peut contenir NumberFormatInfo.PositiveInfinitySymbol , NumberFormatInfo.NegativeInfinitySymbol ou NumberFormatInfo.NaNSymbol pour la culture spécifiée par provider
.The s
parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, or NumberFormatInfo.NaNSymbol for the culture specified by provider
. En fonction de la valeur de style
, il peut également prendre la forme suivante :Depending on the value of style
, it can also take the form:
[WS] [ $ ] [Sign] [chiffres intégraux,]chiffres intégraux[. [ fractions-chiffres]] [E [signe]chiffres exponentiels] [WS][ws] [$] [sign][integral-digits,]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]
Les éléments encadrés par des crochets ([et]) sont facultatifs.Elements framed in square brackets ([ and ]) are optional. Le tableau suivant décrit chaque élément.The following table describes each element.
ÉlémentElement | DescriptionDescription |
---|---|
wsws | Une série d’espaces blancs.A series of white-space characters. Un espace blanc peut apparaître au début de s si style comprend l' NumberStyles.AllowLeadingWhite indicateur, et il peut apparaître à la fin de s si style comprend l' NumberStyles.AllowTrailingWhite indicateur.White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag. |
$ | Symbole monétaire propre à la culture.A culture-specific currency symbol. Sa position dans la chaîne est définie par les NumberFormatInfo.CurrencyNegativePattern NumberFormatInfo.CurrencyPositivePattern Propriétés et de la culture actuelle.Its position in the string is defined by the NumberFormatInfo.CurrencyNegativePattern and NumberFormatInfo.CurrencyPositivePattern properties of the current culture. Le symbole monétaire de la culture actuelle peut apparaître dans s si style comprend l' NumberStyles.AllowCurrencySymbol indicateur.The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag. |
signsign | Symbole de signe négatif (-) ou symbole de signe positif (+).A negative sign symbol (-) or a positive sign symbol (+). Le signe peut apparaître au début de s si style comprend l' NumberStyles.AllowLeadingSign indicateur, et il peut apparaître à la fin de s si style contient l' NumberStyles.AllowTrailingSign indicateur.The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. Les parenthèses peuvent être utilisées dans s pour indiquer une valeur négative si style comprend l' NumberStyles.AllowParentheses indicateur.Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag. |
chiffres intégrauxintegral-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie entière du nombre.A series of digits ranging from 0 to 9 that specify the integral part of the number. L’élément digit-Integral peut être absent si la chaîne contient l’élément fractionnaires-digits .The integral-digits element can be absent if the string contains the fractional-digits element. |
,, | Séparateur de groupe spécifique à la culture.A culture-specific group separator. Le symbole de séparateur de groupe de la culture actuelle peut apparaître dans s si style contient l' NumberStyles.AllowThousands indicateurThe current culture's group separator symbol can appear in s if style includes the NumberStyles.AllowThousands flag |
.. | Symbole de virgule décimale propre à la culture.A culture-specific decimal point symbol. Le symbole de virgule décimale de la culture actuelle peut apparaître dans s si style comprend l' NumberStyles.AllowDecimalPoint indicateur.The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. |
chiffres fractionnairesfractional-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie fractionnaire du nombre.A series of digits ranging from 0 to 9 that specify the fractional part of the number. Les chiffres fractionnaires peuvent apparaître dans s si style comprend l' NumberStyles.AllowDecimalPoint indicateur.Fractional digits can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. |
EE | Caractère « e » ou « E », qui indique que la valeur est représentée en notation exponentielle (scientifique).The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. Le s paramètre peut représenter un nombre en notation exponentielle si style contient l' NumberStyles.AllowExponent indicateur.The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag. |
chiffres exponentielsexponential-digits | Série de chiffres comprise entre 0 et 9 qui spécifient un exposant.A series of digits ranging from 0 to 9 that specify an exponent. |
Notes
Les caractères null de fin (U + 0000) dans s
sont ignorés par l’opération d’analyse, quelle que soit la valeur de l' style
argument.Any terminating NUL (U+0000) characters in s
are ignored by the parsing operation, regardless of the value of the style
argument.
Une chaîne avec des chiffres uniquement (qui correspond au NumberStyles.None style) est toujours analysée correctement si elle se trouve dans la plage Double du type.A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully if it is in the range of the Double type. Les membres restants System.Globalization.NumberStyles contrôlent les éléments qui peuvent être présents, mais qui ne doivent pas être présents, dans la chaîne d’entrée.The remaining System.Globalization.NumberStyles members control elements that may be present, but are not required to be present, in the input string. Le tableau suivant indique la manière dont les NumberStyles indicateurs individuels affectent les éléments qui peuvent être présents dans s
.The following table indicates how individual NumberStyles flags affect the elements that may be present in s
.
Valeur NumberStylesNumberStyles value | Éléments autorisés dans s en plus des chiffresElements permitted in s in addition to digits |
---|---|
None | Élément de chiffres intégraux uniquement.The integral-digits element only. |
AllowDecimalPoint | Éléments virgule décimale (.) et chiffres fractionnaires .The decimal point (.) and fractional-digits elements. |
AllowExponent | Caractère « e » ou « E », qui indique une notation exponentielle.The "e" or "E" character, which indicates exponential notation. Cet indicateur prend lui-même en charge les valeurs des chiffres E. des indicateurs supplémentaires sont nécessaires pour analyser correctement les chaînes avec des éléments tels que les signes positif ou négatif et les symboles de virgule décimale.This flag by itself supports values in the form digits E digits; additional flags are needed to successfully parse strings with such elements as positive or negative signs and decimal point symbols. |
AllowLeadingWhite | Élément WS au début de s .The ws element at the beginning of s . |
AllowTrailingWhite | Élément WS à la fin de s .The ws element at the end of s . |
AllowLeadingSign | Élément signe au début de s .The sign element at the beginning of s . |
AllowTrailingSign | Élément signe à la fin de s .The sign element at the end of s . |
AllowParentheses | Élément de signe sous forme de parenthèses entourant la valeur numérique.The sign element in the form of parentheses enclosing the numeric value. |
AllowThousands | Élément de séparateur des milliers (,).The thousands separator (,) element. |
AllowCurrencySymbol | Élément Currency ($).The currency ($) element. |
Currency | Tous les éléments.All elements. Toutefois, s ne peut pas représenter un nombre hexadécimal ou un nombre en notation exponentielle.However, s cannot represent a hexadecimal number or a number in exponential notation. |
Float | L’élément WS au début ou à la fin de s , se connecte au début de s et le symbole de virgule décimale (.).The ws element at the beginning or end of s , sign at the beginning of s , and the decimal point (.) symbol. Le s paramètre peut également utiliser la notation exponentielle.The s parameter can also use exponential notation. |
Number | Les ws sign éléments,, séparateur de milliers (,) et virgule décimale (.).The ws , sign , thousands separator (,) and decimal point (.) elements. |
Any | Tous les éléments.All elements. Toutefois, s ne peut pas représenter un nombre hexadécimal.However, s cannot represent a hexadecimal number. |
Le provider
paramètre est une IFormatProvider implémentation dont la GetFormat méthode retourne un NumberFormatInfo objet qui fournit des informations spécifiques à la culture utilisées pour interpréter le format de s
.The provider
parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that supplies culture-specific information used in interpreting the format of s
. En général, il s’agit d’un NumberFormatInfo CultureInfo objet ou.Typically, it is a NumberFormatInfo or CultureInfo object. Si provider
est null
ou qu’un NumberFormatInfo ne peut pas être obtenu, les informations de mise en forme de la culture système actuelle sont utilisées.If provider
is null
or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.
En règle générale, si vous transmettez Double.Parse à la méthode une chaîne créée en appelant la Double.ToString méthode, la Double valeur d’origine est retournée.Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. Toutefois, en raison d’une perte de précision, les valeurs peuvent ne pas être égales.However, because of a loss of precision, the values may not be equal. En outre, toute tentative d’analyse de la représentation sous forme de chaîne de MinValue ou de Double.MaxValue échoue à effectuer un aller-retour.In addition, attempting to parse the string representation of either MinValue or Double.MaxValue fails to round-trip. Sur .NET Framework et .NET Core 2,2 et les versions antérieures, il lève une exception OverflowException .On .NET Framework and .NET Core 2.2 and previous versions, it throws an OverflowException. Sur .NET Core 3,0 et versions ultérieures, il retourne Double.NegativeInfinity si vous essayez d’analyser MinValue ou Double.PositiveInfinity si vous essayez d’analyser MaxValue .On .NET Core 3.0 and later versions, it returns Double.NegativeInfinity if you attempt to parse MinValue or Double.PositiveInfinity if you attempt to parse MaxValue. L'exemple suivant illustre cette situation.The following example provides an illustration.
string value;
value = Double.MinValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
value = Double.MaxValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// Format without the default precision.
value = Double.MinValue.ToString("G17");
try
{
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException)
{
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// The example displays the following output:
// -1.79769313486232E+308 is outside the range of the Double type.
// 1.79769313486232E+308 is outside the range of the Double type.
// -1.79769313486232E+308
Dim value As String
value = Double.MinValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
value = Double.MaxValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' Format without the default precision.
value = Double.MinValue.ToString("G17")
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' The example displays the following output:
' -1.79769313486232E+308 is outside the range of the Double type.
' 1.79769313486232E+308 is outside the range of the Double type.
' -1.79769313486232E+308
Sur .NET Framework et .NET Core 2,2 et les versions antérieures, si s
est en dehors des limites du Double type de données, la Parse(String, NumberStyles, IFormatProvider) méthode lève une OverflowException .On .NET Framework and .NET Core 2.2 and earlier versions, if s
is out of range of the Double data type, the Parse(String, NumberStyles, IFormatProvider) method throws an OverflowException.
Sur .NET Core 3,0 et versions ultérieures, aucune exception n’est levée lorsque s
est hors de la plage du Double type de données.On .NET Core 3.0 and later versions, no exception is thrown when s
is out of range of the Double data type. Dans la plupart des cas, la Parse(String, NumberStyles, IFormatProvider) méthode retourne Double.PositiveInfinity ou Double.NegativeInfinity .In most cases, the Parse(String, NumberStyles, IFormatProvider) method will return Double.PositiveInfinity or Double.NegativeInfinity. Toutefois, il existe un petit ensemble de valeurs qui sont considérées comme plus proches des valeurs maximales ou minimales de Double que l’infini positif ou négatif.However, there is a small set of values that are considered to be closer to the maximum or minimum values of Double than to positive or negative infinity. Dans ce cas, la méthode retourne Double.MaxValue ou Double.MinValue .In those cases, the method returns Double.MaxValue or Double.MinValue.
Si un séparateur est rencontré dans le s
paramètre au cours d’une opération d’analyse, et que la devise ou le nombre décimal applicable et les séparateurs de groupes sont identiques, l’opération d’analyse suppose que le séparateur est un séparateur décimal plutôt qu’un séparateur de groupes.If a separator is encountered in the s
parameter during a parse operation, and the applicable currency or number decimal and group separators are the same, the parse operation assumes that the separator is a decimal separator rather than a group separator. Pour plus d’informations sur les séparateurs, consultez CurrencyDecimalSeparator ,, NumberDecimalSeparator CurrencyGroupSeparator et NumberGroupSeparator .For more information about separators, see CurrencyDecimalSeparator, NumberDecimalSeparator, CurrencyGroupSeparator, and NumberGroupSeparator.
Voir aussi
S’applique à
Parse(String, IFormatProvider)
Convertit la représentation sous forme de chaîne d'un nombre dans un format propre à la culture spécifié en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent.
public:
static double Parse(System::String ^ s, IFormatProvider ^ provider);
public static double Parse (string s, IFormatProvider provider);
public static double Parse (string s, IFormatProvider? provider);
static member Parse : string * IFormatProvider -> double
Public Shared Function Parse (s As String, provider As IFormatProvider) As Double
Paramètres
- s
- String
Chaîne contenant un nombre à convertir.A string that contains a number to convert.
- provider
- IFormatProvider
Objet qui fournit des informations de mise en forme propres à la culture sur s
.An object that supplies culture-specific formatting information about s
.
Retours
Nombre à virgule flottante double précision équivalant à la valeur numérique ou au symbole spécifié dans s
.A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s
.
Exceptions
s
a la valeur null
.s
is null
.
s
ne représente pas un nombre dans un format valide.s
does not represent a number in a valid format.
.NET Framework et .NET Core 2.2 et versions antérieures uniquement : s
représente un nombre inférieur à MinValue ou supérieur à MaxValue..NET Framework and .NET Core 2.2 and earlier versions only: s
represents a number that is less than MinValue or greater than MaxValue.
Exemples
L’exemple suivant est le gestionnaire d’événements de clic de bouton d’un formulaire Web.The following example is the button click event handler of a Web form. Elle utilise le tableau retourné par la HttpRequest.UserLanguages propriété pour déterminer les paramètres régionaux de l’utilisateur.It uses the array returned by the HttpRequest.UserLanguages property to determine the user's locale. Il instancie ensuite un CultureInfo objet qui correspond à ces paramètres régionaux.It then instantiates a CultureInfo object that corresponds to that locale. L' NumberFormatInfo objet qui appartient à cet CultureInfo objet est ensuite transmis à la Parse(String, IFormatProvider) méthode pour convertir l’entrée de l’utilisateur en Double valeur.The NumberFormatInfo object that belongs to that CultureInfo object is then passed to the Parse(String, IFormatProvider) method to convert the user's input to a Double value.
protected void OkToDouble_Click(object sender, EventArgs e)
{
string locale;
double 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 = Double.Parse(this.inputNumber.Text, culture.NumberFormat);
}
catch (FormatException)
{
return;
}
catch (OverflowException)
{
return;
}
// Output number to label on web form
this.outputNumber.Text = "Number is " + number.ToString();
}
Protected Sub OkToDouble_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkToDouble.Click
Dim locale As String
Dim culture As CultureInfo
Dim number As Double
' Return if string is empty
If String.IsNullOrEmpty(Me.inputNumber.Text) Then Exit Sub
' Get locale of web request to determine possible format of number
If Request.UserLanguages.Length = 0 Then Exit Sub
locale = Request.UserLanguages(0)
If String.IsNullOrEmpty(locale) Then Exit Sub
' Instantiate CultureInfo object for the user's locale
culture = New CultureInfo(locale)
' Convert user input from a string to a number
Try
number = Double.Parse(Me.inputNumber.Text, culture.NumberFormat)
Catch ex As FormatException
Exit Sub
Catch ex As Exception
Exit Sub
End Try
' Output number to label on web form
Me.outputNumber.Text = "Number is " & number.ToString()
End Sub
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Cette surcharge de la Parse(String, IFormatProvider) méthode est généralement utilisée pour convertir du texte qui peut être mis en forme de différentes façons en une Double valeur.This overload of the Parse(String, IFormatProvider) method is typically used to convert text that can be formatted in a variety of ways to a Double value. Par exemple, il peut être utilisé pour convertir le texte entré par un utilisateur dans une zone de texte HTML en une valeur numérique.For example, it can be used to convert the text that is entered by a user into an HTML text box to a numeric value.
Le s
paramètre est interprété à l’aide d’une combinaison des NumberStyles.Float NumberStyles.AllowThousands indicateurs et.The s
parameter is interpreted using a combination of the NumberStyles.Float and NumberStyles.AllowThousands flags. Le s
paramètre peut contenir NumberFormatInfo.PositiveInfinitySymbol , NumberFormatInfo.NegativeInfinitySymbol ou NumberFormatInfo.NaNSymbol pour la culture spécifiée par provider
, ou peut contenir une chaîne sous la forme :The s
parameter can contain NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, or NumberFormatInfo.NaNSymbol for the culture specified by provider
, or it can contain a string of the form:
[WS] [signe] chiffres intégraux[. [chiffres fractionnaires]] [E [signe]chiffres exponentiels] [WS][ws][sign]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]
Les éléments facultatifs sont encadrés par des crochets ([et]).Optional elements are framed in square brackets ([ and ]). Les éléments qui contiennent le terme « chiffres » se composent d’une série de caractères numériques compris entre 0 et 9.Elements that contain the term "digits" consist of a series of numeric characters ranging from 0 to 9.
ÉlémentElement | DescriptionDescription |
---|---|
wsws | Une série d’espaces blancs.A series of white-space characters. |
signsign | Symbole de signe négatif (-) ou symbole de signe positif (+).A negative sign symbol (-) or a positive sign symbol (+). |
chiffres intégrauxintegral-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie entière du nombre.A series of digits ranging from 0 to 9 that specify the integral part of the number. Les exécutions de chiffres intégraux peuvent être partitionnées par un symbole de séparateur de groupe.Runs of integral-digits can be partitioned by a group-separator symbol. Par exemple, dans certaines cultures, une virgule (,) sépare les groupes de milliers.For example, in some cultures a comma (,) separates groups of thousands. L’élément digit-Integral peut être absent si la chaîne contient l’élément fractionnaires-digits .The integral-digits element can be absent if the string contains the fractional-digits element. |
.. | Symbole de virgule décimale propre à la culture.A culture-specific decimal point symbol. |
chiffres fractionnairesfractional-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie fractionnaire du nombre.A series of digits ranging from 0 to 9 that specify the fractional part of the number. |
EE | Caractère « e » ou « E », qui indique que la valeur est représentée en notation exponentielle (scientifique).The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. |
chiffres exponentielsexponential-digits | Série de chiffres comprise entre 0 et 9 qui spécifient un exposant.A series of digits ranging from 0 to 9 that specify an exponent. |
Pour plus d’informations sur les formats numériques, consultez la rubrique mise en forme des types .For more information about numeric formats, see the Formatting Types topic.
Le provider
paramètre est une IFormatProvider implémentation dont la GetFormat méthode retourne un NumberFormatInfo objet qui fournit des informations spécifiques à la culture utilisées pour interpréter le format de s
.The provider
parameter is an IFormatProvider implementation whose GetFormat method returns a NumberFormatInfo object that supplies culture-specific information used in interpreting the format of s
. En général, il s’agit d’un NumberFormatInfo CultureInfo objet ou.Typically, it is a NumberFormatInfo or CultureInfo object. Si provider
est null
ou qu’un NumberFormatInfo ne peut pas être obtenu, les informations de mise en forme de la culture système actuelle sont utilisées.If provider
is null
or a NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.
En règle générale, si vous transmettez Double.Parse à la méthode une chaîne créée en appelant la Double.ToString méthode, la Double valeur d’origine est retournée.Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. Toutefois, en raison d’une perte de précision, les valeurs peuvent ne pas être égales.However, because of a loss of precision, the values may not be equal. En outre, toute tentative d’analyse de la représentation sous forme de chaîne de Double.MinValue ou de Double.MaxValue échoue à effectuer un aller-retour.In addition, attempting to parse the string representation of either Double.MinValue or Double.MaxValue fails to round-trip. Sur .NET Framework et .NET Core 2,2 et les versions antérieures, il lève une exception OverflowException .On .NET Framework and .NET Core 2.2 and previous versions, it throws an OverflowException. Sur .NET Core 3,0 et versions ultérieures, il retourne Double.NegativeInfinity si vous essayez d’analyser MinValue ou Double.PositiveInfinity si vous essayez d’analyser MaxValue .On .NET Core 3.0 and later versions, it returns Double.NegativeInfinity if you attempt to parse MinValue or Double.PositiveInfinity if you attempt to parse MaxValue. L'exemple suivant illustre cette situation.The following example provides an illustration.
string value;
value = Double.MinValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
value = Double.MaxValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// Format without the default precision.
value = Double.MinValue.ToString("G17");
try
{
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException)
{
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// The example displays the following output:
// -1.79769313486232E+308 is outside the range of the Double type.
// 1.79769313486232E+308 is outside the range of the Double type.
// -1.79769313486232E+308
Dim value As String
value = Double.MinValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
value = Double.MaxValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' Format without the default precision.
value = Double.MinValue.ToString("G17")
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' The example displays the following output:
' -1.79769313486232E+308 is outside the range of the Double type.
' 1.79769313486232E+308 is outside the range of the Double type.
' -1.79769313486232E+308
Sur .NET Framework et .NET Core 2,2 et les versions antérieures, si s
est en dehors des limites du Double type de données, la Parse(String, IFormatProvider) méthode lève une OverflowException .On .NET Framework and .NET Core 2.2 and earlier versions, if s
is out of range of the Double data type, the Parse(String, IFormatProvider) method throws an OverflowException.
Sur .NET Core 3,0 et versions ultérieures, aucune exception n’est levée lorsque s
est hors de la plage du Double type de données.On .NET Core 3.0 and later versions, no exception is thrown when s
is out of range of the Double data type. Dans la plupart des cas, la Parse(String, IFormatProvider) méthode retourne Double.PositiveInfinity ou Double.NegativeInfinity .In most cases, the Parse(String, IFormatProvider) method will return Double.PositiveInfinity or Double.NegativeInfinity. Toutefois, il existe un petit ensemble de valeurs qui sont considérées comme plus proches des valeurs maximales ou minimales de Double que l’infini positif ou négatif.However, there is a small set of values that are considered to be closer to the maximum or minimum values of Double than to positive or negative infinity. Dans ce cas, la méthode retourne Double.MaxValue ou Double.MinValue .In those cases, the method returns Double.MaxValue or Double.MinValue.
Si un séparateur est rencontré dans le s
paramètre au cours d’une opération d’analyse, et que la devise ou le nombre décimal applicable et les séparateurs de groupes sont identiques, l’opération d’analyse suppose que le séparateur est un séparateur décimal plutôt qu’un séparateur de groupes.If a separator is encountered in the s
parameter during a parse operation, and the applicable currency or number decimal and group separators are the same, the parse operation assumes that the separator is a decimal separator rather than a group separator. Pour plus d’informations sur les séparateurs, consultez CurrencyDecimalSeparator ,, NumberDecimalSeparator CurrencyGroupSeparator et NumberGroupSeparator .For more information about separators, see CurrencyDecimalSeparator, NumberDecimalSeparator, CurrencyGroupSeparator, and NumberGroupSeparator.
Voir aussi
S’applique à
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Convertit une étendue de caractères contenant la représentation sous forme de chaîne d'un nombre dans un style et un format propre à la culture spécifiés en nombre à virgule flottante double précision équivalent.Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent.
public static double Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowTrailingWhite | System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.Integer, IFormatProvider? provider = default);
public static double Parse (ReadOnlySpan<char> s, System.Globalization.NumberStyles style = System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowTrailingWhite | System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.Integer, IFormatProvider provider = default);
static member Parse : ReadOnlySpan<char> * System.Globalization.NumberStyles * IFormatProvider -> double
Public Shared Function Parse (s As ReadOnlySpan(Of Char), Optional style As NumberStyles = System.Globalization.NumberStyles.AllowDecimalPoint | System.Globalization.NumberStyles.AllowExponent | System.Globalization.NumberStyles.AllowLeadingSign | System.Globalization.NumberStyles.AllowLeadingWhite | System.Globalization.NumberStyles.AllowThousands | System.Globalization.NumberStyles.AllowTrailingWhite | System.Globalization.NumberStyles.Float | System.Globalization.NumberStyles.Integer, Optional provider As IFormatProvider = Nothing) As Double
Paramètres
- s
- ReadOnlySpan<Char>
Étendue de caractères qui contient le nombre à convertir.A character span that contains the number to convert.
- style
- NumberStyles
Combinaison d'opérations de bit des valeurs d'énumération qui indiquent les éléments de style qui peuvent être présents dans s
.A bitwise combination of enumeration values that indicate the style elements that can be present in s
. Une valeur typique à spécifier est Float combinée avec AllowThousands.A typical value to specify is Float combined with AllowThousands.
- provider
- IFormatProvider
Objet qui fournit des informations de mise en forme propres à la culture sur s
.An object that supplies culture-specific formatting information about s
.
Retours
Nombre à virgule flottante double précision équivalant à la valeur numérique ou au symbole spécifié dans s
.A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s
.
Exceptions
s
ne représente pas une valeur numérique.s
does not represent a numeric value.
style
n’est pas une valeur NumberStyles.style
is not a NumberStyles value.
-ou--or-
style
est la valeur AllowHexSpecifier.style
is the AllowHexSpecifier value.
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Si s
est hors limites du type de Double données, la méthode retourne Double.NegativeInfinity si s
est inférieur à Double.MinValue et Double.PositiveInfinity si s
est supérieur à Double.MaxValue .If s
is out of range of the Double data type, the method returns Double.NegativeInfinity if s
is less than Double.MinValue and Double.PositiveInfinity if s
is greater than Double.MaxValue.
S’applique à
Parse(String)
Convertit la représentation sous forme de chaîne d'un nombre en nombre à virgule flottante double précision équivalent.Converts the string representation of a number to its double-precision floating-point number equivalent.
public:
static double Parse(System::String ^ s);
public static double Parse (string s);
static member Parse : string -> double
Public Shared Function Parse (s As String) As Double
Paramètres
- s
- String
Chaîne contenant un nombre à convertir.A string that contains a number to convert.
Retours
Nombre à virgule flottante double précision équivalant à la valeur numérique ou au symbole spécifié dans s
.A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s
.
Exceptions
s
a la valeur null
.s
is null
.
s
ne représente pas un nombre dans un format valide.s
does not represent a number in a valid format.
.NET Framework et .NET Core 2.2 et versions antérieures uniquement : s
représente un nombre inférieur à MinValue ou supérieur à MaxValue..NET Framework and .NET Core 2.2 and earlier versions only: s
represents a number that is less than MinValue or greater than MaxValue.
Exemples
L'exemple suivant illustre l'utilisation de la méthode Parse(String).The following example illustrates the use of the Parse(String) method.
public ref class Temperature
{
// Parses the temperature from a string in form
// [ws][sign]digits['F|'C][ws]
public:
static Temperature^ Parse( String^ s )
{
Temperature^ temp = gcnew Temperature;
if ( s->TrimEnd(nullptr)->EndsWith( "'F" ) )
{
temp->Value = Double::Parse( s->Remove( s->LastIndexOf( '\'' ), 2 ) );
}
else
if ( s->TrimEnd(nullptr)->EndsWith( "'C" ) )
{
temp->Celsius = Double::Parse( s->Remove( s->LastIndexOf( '\'' ), 2 ) );
}
else
{
temp->Value = Double::Parse( s );
}
return temp;
}
protected:
// The value holder
double m_value;
public:
property double Value
{
double get()
{
return m_value;
}
void set( double value )
{
m_value = value;
}
}
property double Celsius
{
double get()
{
return (m_value - 32.0) / 1.8;
}
void set( double value )
{
m_value = 1.8 * value + 32.0;
}
}
};
public class Temperature {
// Parses the temperature from a string in form
// [ws][sign]digits['F|'C][ws]
public static Temperature Parse(string s) {
Temperature temp = new Temperature();
if( s.TrimEnd(null).EndsWith("'F") ) {
temp.Value = Double.Parse( s.Remove(s.LastIndexOf('\''), 2) );
}
else if( s.TrimEnd(null).EndsWith("'C") ) {
temp.Celsius = Double.Parse( s.Remove(s.LastIndexOf('\''), 2) );
}
else {
temp.Value = Double.Parse(s);
}
return temp;
}
// The value holder
protected double m_value;
public double Value {
get {
return m_value;
}
set {
m_value = value;
}
}
public double Celsius {
get {
return (m_value-32.0)/1.8;
}
set {
m_value = 1.8*value+32.0;
}
}
}
Public Class Temperature
' Parses the temperature from a string in form
' [ws][sign]digits['F|'C][ws]
Public Shared Function Parse(ByVal s As String) As Temperature
Dim temp As New Temperature()
If s.TrimEnd(Nothing).EndsWith("'F") Then
temp.Value = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2))
Else
If s.TrimEnd(Nothing).EndsWith("'C") Then
temp.Celsius = Double.Parse(s.Remove(s.LastIndexOf("'"c), 2))
Else
temp.Value = Double.Parse(s)
End If
End If
Return temp
End Function 'Parse
' The value holder
Protected m_value As Double
Public Property Value() As Double
Get
Return m_value
End Get
Set(ByVal Value As Double)
m_value = Value
End Set
End Property
Public Property Celsius() As Double
Get
Return (m_value - 32) / 1.8
End Get
Set(ByVal Value As Double)
m_value = Value * 1.8 + 32
End Set
End Property
End Class
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Le s
paramètre peut contenir la culture actuelle, NumberFormatInfo.PositiveInfinitySymbol NumberFormatInfo.NegativeInfinitySymbol , NumberFormatInfo.NaNSymbol ou une chaîne au format :The s
parameter can contain the current culture's NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, NumberFormatInfo.NaNSymbol, or a string of the form:
[WS] [signe] [chiffres intégraux[,]] chiffres intégraux[. [chiffres fractionnaires]] [E [signe]chiffres exponentiels] [WS][ws][sign][integral-digits[,]]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]
Les éléments entre crochets ([ et ]) sont facultatifs.Elements in square brackets ([ and ]) are optional. Le tableau suivant décrit chaque élément.The following table describes each element.
ÉlémentElement | DescriptionDescription |
---|---|
wsws | Une série d’espaces blancs.A series of white-space characters. |
signsign | Symbole de signe négatif (-) ou symbole de signe positif (+).A negative sign symbol (-) or a positive sign symbol (+). Seul un signe de début peut être utilisé.Only a leading sign can be used. |
chiffres intégrauxintegral-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie entière du nombre.A series of digits ranging from 0 to 9 that specify the integral part of the number. Les exécutions de chiffres intégraux peuvent être partitionnées par un symbole de séparateur de groupe.Runs of integral-digits can be partitioned by a group-separator symbol. Par exemple, dans certaines cultures, une virgule (,) sépare les groupes de milliers.For example, in some cultures a comma (,) separates groups of thousands. L’élément digit-Integral peut être absent si la chaîne contient l’élément fractionnaires-digits .The integral-digits element can be absent if the string contains the fractional-digits element. |
,, | Symbole de séparateur des milliers spécifique à la culture.A culture-specific thousands separator symbol. |
.. | Symbole de virgule décimale propre à la culture.A culture-specific decimal point symbol. |
chiffres fractionnairesfractional-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie fractionnaire du nombre.A series of digits ranging from 0 to 9 that specify the fractional part of the number. |
EE | Caractère « e » ou « E », qui indique que la valeur est représentée en notation exponentielle (scientifique).The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. |
chiffres exponentielsexponential-digits | Série de chiffres comprise entre 0 et 9 qui spécifient un exposant.A series of digits ranging from 0 to 9 that specify an exponent. |
Le s
paramètre est interprété à l’aide d’une combinaison des NumberStyles.Float NumberStyles.AllowThousands indicateurs et.The s
parameter is interpreted using a combination of the NumberStyles.Float and NumberStyles.AllowThousands flags. Cela signifie que les espaces blancs et les séparateurs de milliers sont autorisés, par exemple, alors que les symboles monétaires ne le sont pas.This means that white space and thousands separators are allowed, for example, while currency symbols are not. Pour un contrôle plus précis sur les éléments de style autorisés dans s
pour que l’opération d’analyse aboutisse, appelez la Double.Parse(String, NumberStyles) Double.Parse(String, NumberStyles, IFormatProvider) méthode ou.For finer control over which style elements are permitted in s
for the parse operation to succeed, call the Double.Parse(String, NumberStyles) or the Double.Parse(String, NumberStyles, IFormatProvider) method.
Le s
paramètre est interprété à l’aide des informations de mise en forme d’un NumberFormatInfo objet initialisé pour la culture du thread actuel.The s
parameter is interpreted using the formatting information in a NumberFormatInfo object that is initialized for the current thread culture. Pour plus d'informations, consultez CurrentInfo.For more information, see CurrentInfo. Pour analyser une chaîne à l’aide des informations de mise en forme d’une autre culture, appelez la Double.Parse(String, IFormatProvider) Double.Parse(String, NumberStyles, IFormatProvider) méthode ou.To parse a string using the formatting information of some other culture, call the Double.Parse(String, IFormatProvider) or Double.Parse(String, NumberStyles, IFormatProvider) method.
En règle générale, si vous transmettez Double.Parse à la méthode une chaîne créée en appelant la Double.ToString méthode, la Double valeur d’origine est retournée.Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. Toutefois, sur .NET Framework et sur .NET Core 2,2 et les versions antérieures, les valeurs peuvent ne pas être égales en raison d’une perte de précision.However, on .NET Framework and on .NET Core 2.2 and earlier versions, the values may not be equal because of a loss of precision. En outre, toute tentative d’analyse de la représentation sous forme de chaîne de Double.MinValue ou de Double.MaxValue échoue à effectuer un aller-retour.In addition, attempting to parse the string representation of either Double.MinValue or Double.MaxValue fails to round-trip. Sur .NET Framework et .NET Core 2,2 et les versions antérieures, il lève une exception OverflowException .On .NET Framework and .NET Core 2.2 and previous versions, it throws an OverflowException. L'exemple suivant illustre cette situation.The following example provides an illustration.
string value;
value = Double.MinValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
value = Double.MaxValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// Format without the default precision.
value = Double.MinValue.ToString("G17");
try
{
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException)
{
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// The example displays the following output:
// -1.79769313486232E+308 is outside the range of the Double type.
// 1.79769313486232E+308 is outside the range of the Double type.
// -1.79769313486232E+308
Dim value As String
value = Double.MinValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
value = Double.MaxValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' Format without the default precision.
value = Double.MinValue.ToString("G17")
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' The example displays the following output:
' -1.79769313486232E+308 is outside the range of the Double type.
' 1.79769313486232E+308 is outside the range of the Double type.
' -1.79769313486232E+308
Sur .NET Framework et .NET Core 2,2 et les versions antérieures, si s
est en dehors des limites du Double type de données, la Parse(String) méthode lève une OverflowException .On .NET Framework and .NET Core 2.2 and earlier versions, if s
is out of range of the Double data type, the Parse(String) method throws an OverflowException.
Sur .NET Core 3,0 et versions ultérieures, aucune exception n’est levée lorsque s
est hors de la plage du Double type de données.On .NET Core 3.0 and later versions, no exception is thrown when s
is out of range of the Double data type. Dans la plupart des cas, la méthode retourne Double.PositiveInfinity ou Double.NegativeInfinity .In most cases, the method will return Double.PositiveInfinity or Double.NegativeInfinity. Toutefois, il existe un petit ensemble de valeurs qui sont considérées comme plus proches des valeurs maximales ou minimales de Double que l’infini positif ou négatif.However, there is a small set of values that are considered to be closer to the maximum or minimum values of Double than to positive or negative infinity. Dans ce cas, la méthode retourne Double.MaxValue ou Double.MinValue .In those cases, the method returns Double.MaxValue or Double.MinValue.
Si un séparateur est rencontré dans le s
paramètre au cours d’une opération d’analyse, et que la devise ou le nombre décimal applicable et les séparateurs de groupes sont identiques, l’opération d’analyse suppose que le séparateur est un séparateur décimal plutôt qu’un séparateur de groupes.If a separator is encountered in the s
parameter during a parse operation, and the applicable currency or number decimal and group separators are the same, the parse operation assumes that the separator is a decimal separator rather than a group separator. Pour plus d’informations sur les séparateurs, consultez CurrencyDecimalSeparator ,, NumberDecimalSeparator CurrencyGroupSeparator et NumberGroupSeparator .For more information about separators, see CurrencyDecimalSeparator, NumberDecimalSeparator, CurrencyGroupSeparator, and NumberGroupSeparator.
Voir aussi
- ToString()
- TryParse(String, Double)
- Analyse de chaînes numériques dans .NETParsing Numeric Strings in .NET
S’applique à
Parse(String, NumberStyles)
Convertit la représentation sous forme de chaîne d'un nombre dans un style spécifié en nombre à virgule flottante double précision équivalent.Converts the string representation of a number in a specified style to its double-precision floating-point number equivalent.
public:
static double Parse(System::String ^ s, System::Globalization::NumberStyles style);
public static double Parse (string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> double
Public Shared Function Parse (s As String, style As NumberStyles) As Double
Paramètres
- s
- String
Chaîne contenant un nombre à convertir.A string that contains a number to convert.
- style
- NumberStyles
Combinaison d'opérations de bit des valeurs d'énumération qui indiquent les éléments de style qui peuvent être présents dans s
.A bitwise combination of enumeration values that indicate the style elements that can be present in s
. Une valeur typique à spécifier est une combinaison de Float combinée avec AllowThousands.A typical value to specify is a combination of Float combined with AllowThousands.
Retours
Nombre à virgule flottante double précision équivalant à la valeur numérique ou au symbole spécifié dans s
.A double-precision floating-point number that is equivalent to the numeric value or symbol specified in s
.
Exceptions
s
a la valeur null
.s
is null
.
s
ne représente pas un nombre dans un format valide.s
does not represent a number in a valid format.
.NET Framework et .NET Core 2.2 et versions antérieures uniquement : s
représente un nombre inférieur à MinValue ou supérieur à MaxValue..NET Framework and .NET Core 2.2 and earlier versions only: s
represents a number that is less than MinValue or greater than MaxValue.
style
n’est pas une valeur NumberStyles.style
is not a NumberStyles value.
-ou--or-
style
inclut la valeur AllowHexSpecifier.style
includes the AllowHexSpecifier value.
Exemples
L’exemple suivant utilise la Parse(String, NumberStyles) méthode pour analyser les représentations sous forme de chaîne de Double valeurs à l’aide de la culture en-US.The following example uses the Parse(String, NumberStyles) method to parse the string representations of Double values using the en-US culture.
public static void Main()
{
// Set current thread culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
string value;
NumberStyles styles;
// Parse a string in exponential notation with only the AllowExponent flag.
value = "-1.063E-02";
styles = NumberStyles.AllowExponent;
ShowNumericValue(value, styles);
// Parse a string in exponential notation
// with the AllowExponent and Number flags.
styles = NumberStyles.AllowExponent | NumberStyles.Number;
ShowNumericValue(value, styles);
// Parse a currency value with leading and trailing white space, and
// white space after the U.S. currency symbol.
value = " $ 6,164.3299 ";
styles = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
ShowNumericValue(value, styles);
// Parse negative value with thousands separator and decimal.
value = "(4,320.64)";
styles = NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign |
NumberStyles.Float;
ShowNumericValue(value, styles);
styles = NumberStyles.AllowParentheses | NumberStyles.AllowTrailingSign |
NumberStyles.Float | NumberStyles.AllowThousands;
ShowNumericValue(value, styles);
}
private static void ShowNumericValue(string value, NumberStyles styles)
{
double number;
try
{
number = Double.Parse(value, styles);
Console.WriteLine("Converted '{0}' using {1} to {2}.",
value, styles.ToString(), number);
}
catch (FormatException)
{
Console.WriteLine("Unable to parse '{0}' with styles {1}.",
value, styles.ToString());
}
Console.WriteLine();
}
// The example displays the following output to the console:
// Unable to parse '-1.063E-02' with styles AllowExponent.
//
// Converted '-1.063E-02' using AllowTrailingSign, AllowThousands, Float to -0.01063.
//
// Converted ' $ 6,164.3299 ' using Number, AllowCurrencySymbol to 6164.3299.
//
// Unable to parse '(4,320.64)' with styles AllowTrailingSign, AllowParentheses, Float.
//
// Converted '(4,320.64)' using AllowTrailingSign, AllowParentheses, AllowThousands, Float to -4320.64.
Public Sub Main()
' Set current thread culture to en-US.
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
Dim value As String
Dim styles As NumberStyles
' Parse a string in exponential notation with only the AllowExponent flag.
value = "-1.063E-02"
styles = NumberStyles.AllowExponent
ShowNumericValue(value, styles)
' Parse a string in exponential notation
' with the AllowExponent and Number flags.
styles = NumberStyles.AllowExponent Or NumberStyles.Number
ShowNumericValue(value, styles)
' Parse a currency value with leading and trailing white space, and
' white space after the U.S. currency symbol.
value = " $ 6,164.3299 "
styles = NumberStyles.Number Or NumberStyles.AllowCurrencySymbol
ShowNumericValue(value, styles)
' Parse negative value with thousands separator and decimal.
value = "(4,320.64)"
styles = NumberStyles.AllowParentheses Or NumberStyles.AllowTrailingSign _
Or NumberStyles.Float
ShowNumericValue(value, styles)
styles = NumberStyles.AllowParentheses Or NumberStyles.AllowTrailingSign _
Or NumberStyles.Float Or NumberStyles.AllowThousands
ShowNumericValue(value, styles)
End Sub
Private Sub ShowNumericValue(value As String, styles As NumberStyles)
Dim number As Double
Try
number = Double.Parse(value, styles)
Console.WriteLine("Converted '{0}' using {1} to {2}.", _
value, styles.ToString(), number)
Catch e As FormatException
Console.WriteLine("Unable to parse '{0}' with styles {1}.", _
value, styles.ToString())
End Try
Console.WriteLine()
End Sub
' The example displays the following output to the console:
' Unable to parse '-1.063E-02' with styles AllowExponent.
'
' Converted '-1.063E-02' using AllowTrailingSign, AllowThousands, Float to -0.01063.
'
' Converted ' $ 6,164.3299 ' using Number, AllowCurrencySymbol to 6164.3299.
'
' Unable to parse '(4,320.64)' with styles AllowTrailingSign, AllowParentheses, Float.
'
' Converted '(4,320.64)' using AllowTrailingSign, AllowParentheses, AllowThousands, Float to -4320.64.
Remarques
Dans .NET Core 3,0 et versions ultérieures, les valeurs qui sont trop volumineuses pour être représentées sont arrondies à PositiveInfinity ou NegativeInfinity comme requis par la spécification IEEE 754.In .NET Core 3.0 and later, values that are too large to represent are rounded to PositiveInfinity or NegativeInfinity as required by the IEEE 754 specification. Dans les versions antérieures, y compris les .NET Framework, l’analyse d’une valeur trop grande pour être représentée a entraîné un échec.In prior versions, including .NET Framework, parsing a value that was too large to represent resulted in failure.
Le style
paramètre définit les éléments de style (tels que les espaces blancs, les séparateurs de milliers et les symboles monétaires) qui sont autorisés dans le s
paramètre pour que l’opération d’analyse aboutisse.The style
parameter defines the style elements (such as white space, thousands separators, and currency symbols) that are allowed in the s
parameter for the parse operation to succeed. Il doit s’agir d’une combinaison de bits indicateurs de l' NumberStyles énumération.It must be a combination of bit flags from the NumberStyles enumeration. Les membres suivants ne NumberStyles sont pas pris en charge :The following NumberStyles members are not supported:
Le s
paramètre peut contenir le, ou la culture actuelle NumberFormatInfo.PositiveInfinitySymbol NumberFormatInfo.NegativeInfinitySymbol NumberFormatInfo.NaNSymbol .The s
parameter can contain the current culture's NumberFormatInfo.PositiveInfinitySymbol, NumberFormatInfo.NegativeInfinitySymbol, or NumberFormatInfo.NaNSymbol. En fonction de la valeur de style
, il peut également prendre la forme suivante :Depending on the value of style
, it can also take the form:
[WS] [ $ ] [Sign] [chiffres intégraux[,]]chiffres intégraux[. [chiffres fractionnaires]] [E [signe]chiffres exponentiels] [WS][ws][$][sign][integral-digits[,]]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]
Les éléments entre crochets ([ et ]) sont facultatifs.Elements in square brackets ([ and ]) are optional. Le tableau suivant décrit chaque élément.The following table describes each element.
ÉlémentElement | DescriptionDescription |
---|---|
wsws | Une série d’espaces blancs.A series of white-space characters. Un espace blanc peut apparaître au début de s si style comprend l' NumberStyles.AllowLeadingWhite indicateur, et il peut apparaître à la fin de s si style comprend l' NumberStyles.AllowTrailingWhite indicateur.White space can appear at the beginning of s if style includes the NumberStyles.AllowLeadingWhite flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingWhite flag. |
$ | Symbole monétaire propre à la culture.A culture-specific currency symbol. Sa position dans la chaîne est définie par les NumberFormatInfo.CurrencyNegativePattern NumberFormatInfo.CurrencyPositivePattern Propriétés et de la culture actuelle.Its position in the string is defined by the NumberFormatInfo.CurrencyNegativePattern and NumberFormatInfo.CurrencyPositivePattern properties of the current culture. Le symbole monétaire de la culture actuelle peut apparaître dans s si style comprend l' NumberStyles.AllowCurrencySymbol indicateur.The current culture's currency symbol can appear in s if style includes the NumberStyles.AllowCurrencySymbol flag. |
signsign | Symbole de signe négatif (-) ou symbole de signe positif (+).A negative sign symbol (-) or a positive sign symbol (+). Le signe peut apparaître au début de s si style comprend l' NumberStyles.AllowLeadingSign indicateur, et il peut apparaître à la fin de s si style contient l' NumberStyles.AllowTrailingSign indicateur.The sign can appear at the beginning of s if style includes the NumberStyles.AllowLeadingSign flag, and it can appear at the end of s if style includes the NumberStyles.AllowTrailingSign flag. Les parenthèses peuvent être utilisées dans s pour indiquer une valeur négative si style comprend l' NumberStyles.AllowParentheses indicateur.Parentheses can be used in s to indicate a negative value if style includes the NumberStyles.AllowParentheses flag. |
chiffres intégrauxintegral-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie entière du nombre.A series of digits ranging from 0 to 9 that specify the integral part of the number. L’élément digit-Integral peut être absent si la chaîne contient l’élément fractionnaires-digits .The integral-digits element can be absent if the string contains the fractional-digits element. |
,, | Séparateur de groupe spécifique à la culture.A culture-specific group separator. Le symbole de séparateur de groupe de la culture actuelle peut apparaître dans s si style contient l' NumberStyles.AllowThousands indicateurThe current culture's group separator symbol can appear in s if style includes the NumberStyles.AllowThousands flag |
.. | Symbole de virgule décimale propre à la culture.A culture-specific decimal point symbol. Le symbole de virgule décimale de la culture actuelle peut apparaître dans s si style comprend l' NumberStyles.AllowDecimalPoint indicateur.The current culture's decimal point symbol can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. |
chiffres fractionnairesfractional-digits | Série de chiffres comprise entre 0 et 9 qui spécifient la partie fractionnaire du nombre.A series of digits ranging from 0 to 9 that specify the fractional part of the number. Les chiffres fractionnaires peuvent apparaître dans s si style comprend l' NumberStyles.AllowDecimalPoint indicateur.Fractional digits can appear in s if style includes the NumberStyles.AllowDecimalPoint flag. |
EE | Caractère « e » ou « E », qui indique que la valeur est représentée en notation exponentielle (scientifique).The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation. Le s paramètre peut représenter un nombre en notation exponentielle si style contient l' NumberStyles.AllowExponent indicateur.The s parameter can represent a number in exponential notation if style includes the NumberStyles.AllowExponent flag. |
chiffres exponentielsexponential-digits | Série de chiffres comprise entre 0 et 9 qui spécifient un exposant.A series of digits ranging from 0 to 9 that specify an exponent. |
Notes
Les caractères null de fin (U + 0000) dans s
sont ignorés par l’opération d’analyse, quelle que soit la valeur de l' style
argument.Any terminating NUL (U+0000) characters in s
are ignored by the parsing operation, regardless of the value of the style
argument.
Une chaîne avec des chiffres uniquement (qui correspond au NumberStyles.None style) est toujours analysée correctement si elle se trouve dans la plage Double du type.A string with digits only (which corresponds to the NumberStyles.None style) always parses successfully if it is in the range of the Double type. Les membres restants System.Globalization.NumberStyles contrôlent les éléments qui peuvent être présents, mais qui ne doivent pas être présents, dans la chaîne d’entrée.The remaining System.Globalization.NumberStyles members control elements that may be present, but are not required to be present, in the input string. Le tableau suivant indique la manière dont les NumberStyles indicateurs individuels affectent les éléments qui peuvent être présents dans s
.The following table indicates how individual NumberStyles flags affect the elements that may be present in s
.
Valeur NumberStylesNumberStyles value | Éléments autorisés dans s en plus des chiffresElements permitted in s in addition to digits |
---|---|
None | Élément de chiffres intégraux uniquement.The integral-digits element only. |
AllowDecimalPoint | Éléments virgule décimale (.) et chiffres fractionnaires .The decimal point (.) and fractional-digits elements. |
AllowExponent | Caractère « e » ou « E », qui indique une notation exponentielle.The "e" or "E" character, which indicates exponential notation. Cet indicateur prend lui-même en charge les valeurs des chiffres E. des indicateurs supplémentaires sont nécessaires pour analyser correctement les chaînes avec des éléments tels que les signes positif ou négatif et les symboles de virgule décimale.This flag by itself supports values in the form digits E digits; additional flags are needed to successfully parse strings with such elements as positive or negative signs and decimal point symbols. |
AllowLeadingWhite | Élément WS au début de s .The ws element at the beginning of s . |
AllowTrailingWhite | Élément WS à la fin de s .The ws element at the end of s . |
AllowLeadingSign | Élément signe au début de s .The sign element at the beginning of s . |
AllowTrailingSign | Élément signe à la fin de s .The sign element at the end of s . |
AllowParentheses | Élément de signe sous forme de parenthèses entourant la valeur numérique.The sign element in the form of parentheses enclosing the numeric value. |
AllowThousands | Élément de séparateur des milliers (,).The thousands separator (,) element. |
AllowCurrencySymbol | Élément Currency ($).The currency ($) element. |
Currency | Tous les éléments.All elements. Toutefois, s ne peut pas représenter un nombre hexadécimal ou un nombre en notation exponentielle.However, s cannot represent a hexadecimal number or a number in exponential notation. |
Float | L’élément WS au début ou à la fin de s , se connecte au début de s et le symbole de virgule décimale (.).The ws element at the beginning or end of s , sign at the beginning of s , and the decimal point (.) symbol. Le s paramètre peut également utiliser la notation exponentielle.The s parameter can also use exponential notation. |
Number | Les ws sign éléments,, séparateur de milliers (,) et virgule décimale (.).The ws , sign , thousands separator (,) and decimal point (.) elements. |
Any | Tous les éléments.All elements. Toutefois, s ne peut pas représenter un nombre hexadécimal.However, s cannot represent a hexadecimal number. |
Le s
paramètre est analysé à l’aide des informations de mise en forme d’un NumberFormatInfo objet initialisé pour la culture système en cours.The s
parameter is parsed using the formatting information in a NumberFormatInfo object that is initialized for the current system culture. Pour plus d'informations, consultez CurrentInfo.For more information, see CurrentInfo.
En règle générale, si vous transmettez Double.Parse à la méthode une chaîne créée en appelant la Double.ToString méthode, la Double valeur d’origine est retournée.Ordinarily, if you pass the Double.Parse method a string that is created by calling the Double.ToString method, the original Double value is returned. Toutefois, en raison d’une perte de précision, les valeurs peuvent ne pas être égales.However, because of a loss of precision, the values may not be equal. En outre, toute tentative d’analyse de la représentation sous forme de chaîne de Double.MinValue ou de Double.MaxValue échoue à effectuer un aller-retour.In addition, attempting to parse the string representation of either Double.MinValue or Double.MaxValue fails to round-trip. Sur .NET Framework et .NET Core 2,2 et les versions antérieures, il lève une exception OverflowException .On .NET Framework and .NET Core 2.2 and previous versions, it throws an OverflowException. Sur .NET Core 3,0 et versions ultérieures, il retourne Double.NegativeInfinity si vous essayez d’analyser MinValue ou Double.PositiveInfinity si vous essayez d’analyser MaxValue .On .NET Core 3.0 and later versions, it returns Double.NegativeInfinity if you attempt to parse MinValue or Double.PositiveInfinity if you attempt to parse MaxValue. L'exemple suivant illustre cette situation.The following example provides an illustration.
string value;
value = Double.MinValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
value = Double.MaxValue.ToString();
try {
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException) {
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// Format without the default precision.
value = Double.MinValue.ToString("G17");
try
{
Console.WriteLine(Double.Parse(value));
}
catch (OverflowException)
{
Console.WriteLine($"{value} is outside the range of the Double type.");
}
// The example displays the following output:
// -1.79769313486232E+308 is outside the range of the Double type.
// 1.79769313486232E+308 is outside the range of the Double type.
// -1.79769313486232E+308
Dim value As String
value = Double.MinValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
value = Double.MaxValue.ToString()
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' Format without the default precision.
value = Double.MinValue.ToString("G17")
Try
Console.WriteLine(Double.Parse(value))
Catch e As OverflowException
Console.WriteLine($"{value} is outside the range of the Double type.")
End Try
' The example displays the following output:
' -1.79769313486232E+308 is outside the range of the Double type.
' 1.79769313486232E+308 is outside the range of the Double type.
' -1.79769313486232E+308
Sur .NET Framework et .NET Core 2,2 et les versions antérieures, si s
est en dehors des limites du Double type de données, la Parse(String, NumberStyles) méthode lève une OverflowException .On .NET Framework and .NET Core 2.2 and earlier versions, if s
is out of range of the Double data type, the Parse(String, NumberStyles) method throws an OverflowException.
Sur .NET Core 3,0 et versions ultérieures, aucune exception n’est levée lorsque s
est hors de la plage du Double type de données.On .NET Core 3.0 and later versions, no exception is thrown when s
is out of range of the Double data type. Dans la plupart des cas, la Parse(String, NumberStyles) méthode retourne Double.PositiveInfinity ou Double.NegativeInfinity .In most cases, the Parse(String, NumberStyles) method will return Double.PositiveInfinity or Double.NegativeInfinity. Toutefois, il existe un petit ensemble de valeurs qui sont considérées comme plus proches des valeurs maximales ou minimales de Double que l’infini positif ou négatif.However, there is a small set of values that are considered to be closer to the maximum or minimum values of Double than to positive or negative infinity. Dans ce cas, la méthode retourne Double.MaxValue ou Double.MinValue .In those cases, the method returns Double.MaxValue or Double.MinValue.
Si un séparateur est rencontré dans le s
paramètre au cours d’une opération d’analyse, et que la devise ou le nombre décimal applicable et les séparateurs de groupes sont identiques, l’opération d’analyse suppose que le séparateur est un séparateur décimal plutôt qu’un séparateur de groupes.If a separator is encountered in the s
parameter during a parse operation, and the applicable currency or number decimal and group separators are the same, the parse operation assumes that the separator is a decimal separator rather than a group separator. Pour plus d’informations sur les séparateurs, consultez CurrencyDecimalSeparator ,, NumberDecimalSeparator CurrencyGroupSeparator et NumberGroupSeparator .For more information about separators, see CurrencyDecimalSeparator, NumberDecimalSeparator, CurrencyGroupSeparator, and NumberGroupSeparator.