Edit

Share via


nfloat.Parse Method

Definition

Overloads

Parse(String)

Converts the string representation of a number to its double-precision floating-point number equivalent.

Parse(String, NumberStyles)
Parse(String, IFormatProvider)

Converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent.

Parse(String, NumberStyles, IFormatProvider)

Parse(String)

Converts the string representation of a number to its double-precision floating-point number equivalent.

public static nfloat Parse (string s);
static member Parse : string -> nfloat

Parameters

s
String

A string that contains a number to convert.

Returns

A nfloat floating-point number that is equivalent to the numeric value or symbol specified in s.

Remarks

The s parameter can contain the current culture's P:System.Globalization.NumberFormatInfo.PositiveInfinitySymbolP:System.Globalization.NumberFormatInfo.NegativeInfinitySymbolP:System.Globalization.NumberFormatInfo.NaNSymbol, or a string of the form:

[ws][sign][integral-digits[,]]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]

Elements in square brackets ([ and ]) are optional. The following table describes each element.

Element

Description

ws

A series of white-space characters.

sign

A negative sign symbol (-) or a positive sign symbol (+). Only a leading sign can be used.

integral-digits

A series of digits ranging from 0 to 9 that specify the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. For example, in some cultures a comma (,) separates groups of thousands. The integral-digits element can be absent if the string contains the fractional-digits element.

,

A culture-specific thousands separator symbol.

.

A culture-specific decimal point symbol.

fractional-digits

A series of digits ranging from 0 to 9 that specify the fractional part of the number.

E

The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation.

exponential-digits

A series of digits ranging from 0 to 9 that specify an exponent.

The s parameter is interpreted using a combination of the F:System.Globalization.NumberStyles.Float and F:System.Globalization.NumberStyles.AllowThousands flags. This means that white space and thousands separators are allowed, for example, while currency symbols are not. For finer control over which style elements are permitted in s for the parse operation to succeed, call the M:System.Double.Parse(System.String,System.Globalization.NumberStyles) or the M:System.Double.Parse(System.String,System.Globalization.NumberStyles,System.IFormatProvider) method.

The s parameter is interpreted using the formatting information in a T:System.Globalization.NumberFormatInfo object that is initialized for the current thread culture. For more information, see P:System.Globalization.NumberFormatInfo.CurrentInfo. To parse a string using the formatting information of some other culture, call the M:System.Double.Parse(System.String,System.IFormatProvider) or M:System.Double.Parse(System.String,System.Globalization.NumberStyles,System.IFormatProvider) method.

Ordinarily, if you pass the M:System.Double.Parse* method a string that is created by calling the M:System.Double.ToString* method, the original T:System.Double value is returned. However, because of a loss of precision, the values may not be equal. In addition, attempting to parse the string representation of either F:System.Double.MinValue or F:System.Double.MaxValue throws an T:System.OverflowException, as the following example illustrates.

code reference: System.Double.Parse#3

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. For more information about separators, see P:System.Globalization.NumberFormatInfo.CurrencyDecimalSeparatorP:System.Globalization.NumberFormatInfo.NumberDecimalSeparatorP:System.Globalization.NumberFormatInfo.CurrencyGroupSeparator, and P:System.Globalization.NumberFormatInfo.NumberGroupSeparator.

Applies to

Parse(String, NumberStyles)

public static nfloat Parse (string s, System.Globalization.NumberStyles style);
static member Parse : string * System.Globalization.NumberStyles -> nfloat

Parameters

s
String
style
NumberStyles

Returns

Applies to

Parse(String, IFormatProvider)

Converts the string representation of a number in a specified culture-specific format to its double-precision floating-point number equivalent.

public static nfloat Parse (string s, IFormatProvider provider);
static member Parse : string * IFormatProvider -> nfloat

Parameters

s
String

A string that contains a number to convert.

provider
IFormatProvider

An object that supplies culture-specific formatting information about s.

Returns

A nfloat floating-point number that is equivalent to the numeric value or symbol specified in s.

Remarks

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 nfloat value. 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.

The s parameter is interpreted using a combination of the F:System.Globalization.NumberStyles.Float and F:System.Globalization.NumberStyles.AllowThousands flags. The s parameter can contain P:System.Globalization.NumberFormatInfo.PositiveInfinitySymbolP:System.Globalization.NumberFormatInfo.NegativeInfinitySymbol, or P:System.Globalization.NumberFormatInfo.NaNSymbol for the culture specified by provider, or it can contain a string of the form:

[ws][sign]integral-digits[.[fractional-digits]][E[sign]exponential-digits][ws]

Optional elements are framed in square brackets ([ and ]). Elements that contain the term "digits" consist of a series of numeric characters ranging from 0 to 9.

Element

Description

ws

A series of white-space characters.

sign

A negative sign symbol (-) or a positive sign symbol (+).

integral-digits

A series of digits ranging from 0 to 9 that specify the integral part of the number. Runs of integral-digits can be partitioned by a group-separator symbol. For example, in some cultures a comma (,) separates groups of thousands. The integral-digits element can be absent if the string contains the fractional-digits element.

.

A culture-specific decimal point symbol.

fractional-digits

A series of digits ranging from 0 to 9 that specify the fractional part of the number.

E

The "e" or "E" character, which indicates that the value is represented in exponential (scientific) notation.

exponential-digits

A series of digits ranging from 0 to 9 that specify an exponent.

The provider parameter is an T:System.IFormatProvider implementation whose M:System.IFormatProvider.GetFormat(System.Type) method returns a T:System.Globalization.NumberFormatInfo object that supplies culture-specific information used in interpreting the format of s. Typically, it is a T:System.Globalization.NumberFormatInfo or T:System.Globalization.CultureInfo object. If provider is null or a T:System.Globalization.NumberFormatInfo cannot be obtained, the formatting information for the current system culture is used.

Ordinarily, if you pass the M:System.nfloat.Parse* method a string that is created by calling the M:System.nfloat.ToString* method, the original nfloat value is returned. However, because of a loss of precision, the values may not be equal. In addition, attempting to parse the string representation of either MinValue or MaxValue throws an T:System.OverflowException.

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. For more information about separators, see P:System.Globalization.NumberFormatInfo.CurrencyDecimalSeparatorP:System.Globalization.NumberFormatInfo.NumberDecimalSeparatorP:System.Globalization.NumberFormatInfo.CurrencyGroupSeparator, and P:System.Globalization.NumberFormatInfo.NumberGroupSeparator.

Applies to

Parse(String, NumberStyles, IFormatProvider)

public static nfloat Parse (string s, System.Globalization.NumberStyles style, IFormatProvider provider);
static member Parse : string * System.Globalization.NumberStyles * IFormatProvider -> nfloat

Parameters

s
String
style
NumberStyles
provider
IFormatProvider

Returns

Applies to