Method ToString
ToString()
Returns a full-precision decimal form string representation of this value using the current culture.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string |
Overrides
ToString(string?, IFormatProvider?)
Returns a string representation of this value.
Declaration
public string ToString(string? format, IFormatProvider? formatProvider = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | format | The string format to use. The "G" format is used if none is provided. |
| IFormatProvider | formatProvider | The format provider that will be used to obtain number format information. The current culture is used if none is provided. |
Returns
| Type | Description |
|---|---|
| string |
Implements
Remarks
String format is composed of a format specifier followed by an optional precision specifier.
Format specifiers:
| Specifier | Name | Description |
|---|---|---|
| "G" | General | Default format specifier if none is provided. Precision specifier determines the number of significant digits. If the precision specifier is omitted then the value is written out in full precision decimal form. If a precision specifier is provided then the value is rounded to that many significant digits and the more compact of either decimal form or scientific notation is used. Scientific notation exponents contain a sign and at least two digits. |
| "F" | Fixed-point | Precision specifier determines the number of decimal digits. Default value is NumberDecimalDigits. |
| "N" | Number | Like fixed-point, but also outputs group separators. Precision specifier determines the number of decimal digits. Default value is NumberDecimalDigits. |
| "E" | Exponential | Exponential (scientific) notation. Precision specifier determines the number of decimal digits. Default value is 6. The exponent always contains a sign and at least three digits. |
| "C" | Currency | Precision specifier determines the number of decimal digits. Default value is CurrencyDecimalDigits. |
| "P" | Percentage | Precision specifier determines the number of decimal digits. Default value is PercentDecimalDigits. |
| "R" | Round-trip | Outputs the mantissa followed by E and then the exponent, always using the InvariantCulture. |
Format specifiers are case-insensitive, but lowercase "g" and "e" specifiers produce a lowercase exponent character ("e") when scientific notation is used, matching the behavior of the standard .NET numeric types.
Values are rounded using MidpointAwayFromZero when the format does not have enough precision to represent the value exactly.