Convert Double to String in .NET Framework, avoiding scientific notation
In the .NET Framework, converting a double to a floating point string without using scientific notation can be challenging. Standard number formats and custom formats do not provide adequate control over decimal point precision.
However, a general solution can preserve up to 339 decimal places:
<code>doubleValue.ToString("0." + new string('#', 339))</code>
This format ensures that all numbers, including very large or very small values, are displayed in non-scientific notation. Because efficient unmanaged CLR code handles the formatting process, its performance is better than regular expression or string manipulation methods.
To improve usability and performance, formats can be defined as constants:
<code>public static class FormatStrings { public const string DoubleFixedPoint = "0.###################################################################################################################################################################################################################################################################################################################################################"; }</code>
While this solution handles all double values efficiently, it is not lossless as rounding occurs during display. If lossless conversion is required, refer to Lothing's answer, which provides a solution that supports round-trips using fixed-point representation.
The above is the detailed content of How to Convert a Double to a String Without Scientific Notation in .NET Framework?. For more information, please follow other related articles on the PHP Chinese website!