CKTIS / C#
Double.Parse — converting text to double
Double.Parse converts text to double. Culture determines separators, while NumberStyles controls the permitted syntax.
Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification
Syntax
double Double.Parse(string s)
double Double.Parse(string s, IFormatProvider? provider)
double Double.Parse(string s, NumberStyles style, IFormatProvider? provider)Double.Parse returns a double; double.Parse names the same method. By default, it uses the current culture and NumberStyles.Float | NumberStyles.AllowThousands.
Using CultureInfo.InvariantCulture as the provider makes separator rules independent of system settings. Passing an explicit provider is not enough by itself: a CultureInfo can reflect user overrides, and if the provider does not supply a NumberFormatInfo, the method falls back to the current culture. NumberStyles.Float permits surrounding whitespace, a leading sign, a decimal separator, and an exponent, but not group separators.
For overloads accepting string, null causes ArgumentNullException, and malformed input causes FormatException. Invalid style causes ArgumentException. Use Double.TryParse for expected input failures.
In .NET 10, overflow usually produces PositiveInfinity or NegativeInfinity, not OverflowException; near-boundary values may round to a finite value. Culture-specific symbols for NaN and infinity are also accepted.
Examples
using System;
using System.Globalization;
string text = " 1.25e2 ";
double value = Double.Parse(text, NumberStyles.Float, CultureInfo.InvariantCulture);
Console.WriteLine(value.ToString("F2", CultureInfo.InvariantCulture));Result
125.00
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.