Class FloatToTextConverter
- Namespace
- Switchboard
- Assembly
- Switchboard.TextConverter.dll
Converts floating-point numbers into strings of characters without allocating memory for garbage collection.
public sealed class FloatToTextConverter
- Inheritance
-
FloatToTextConverter
Fields
MaxCharacterCount
Gets the maximum number of characters necessary to represent the exact value of the longest double-precision floating-point number.
public const int MaxCharacterCount = 1077
RoundTripDoublePrecision
Gets the maximum number of significant digits that may be necessary to represent the value as text for a round trip conversion from a double into text, then back into a double, without changing the binary value of the double.
public const int RoundTripDoublePrecision = 17
RoundTripFloatPrecision
Gets the maximum number of significant digits that may be necessary to represent the value as text for a round trip conversion from a float into text, then back into a float, without changing the binary value of the float.
public const int RoundTripFloatPrecision = 9
Properties
ThreadStaticInstance
Gets a ThreadStaticAttribute instance of the class.
public static FloatToTextConverter ThreadStaticInstance { get; }
Methods
ConvertToText(double, Span<char>)
Converts a double-precision floating-point number into a Span<T> of characters.
public int ConvertToText(double value, Span<char> result)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.
ConvertToText(double, Span<char>, FloatFormatInfo)
Converts a double-precision floating-point number into a Span<T> of characters.
public int ConvertToText(double value, Span<char> result, FloatFormatInfo format)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
formatFloatFormatInfoInformation used to the format of the result.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.
ConvertToText(double, Span<char>, FloatFormatInfo, out bool)
Converts a double-precision floating-point number into a Span<T> of characters, without a negative sign.
public int ConvertToText(double value, Span<char> result, FloatFormatInfo format, out bool valueIsNegative)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
formatFloatFormatInfoInformation used to the format of the result.
valueIsNegativeboolThe value will be true if the
valueis a negative number.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.
ConvertToText(double, Span<char>, int)
Converts a double-precision floating-point number into a Span<T> of characters.
public int ConvertToText(double value, Span<char> result, int minFractionalDigits)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
minFractionalDigitsintThe minimum number of fractional digits to display.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsis less than zero.
ConvertToText(double, Span<char>, int, int)
Converts a double-precision floating-point number into a Span<T> of characters.
public int ConvertToText(double value, Span<char> result, int minFractionalDigits, int maxFractionalDigits)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
minFractionalDigitsintThe minimum number of fractional digits to display.
maxFractionalDigitsintThe maximum number of fractional digits to display.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsormaxFractionalDigitsare less than zero, or ifminFractionalDigitsis greater thanmaxFractionalDigits.
ConvertToText(double, Span<char>, int, int, bool)
Converts a double-precision floating-point number into a Span<T> of characters.
public int ConvertToText(double value, Span<char> result, int minFractionalDigits, int maxFractionalDigits, bool groupDigits)
Parameters
valuedoubleThe number to convert.
resultSpan<char>The target to contain the result of the conversion.
minFractionalDigitsintThe minimum number of fractional digits to display.
maxFractionalDigitsintThe maximum number of fractional digits to display.
groupDigitsboolThe maximum number of fractional digits to display.
Returns
- int
Returns the number of characters in the result.
Exceptions
- IndexOutOfRangeException
Thrown if
resultis not long enough to hold the value.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsormaxFractionalDigitsare less than zero, or ifminFractionalDigitsis greater thanmaxFractionalDigits.
ConvertToText<T>(double, T, ReadOnlySpanAction<char, T>)
Converts a double-precision floating-point number into a Span<T> of characters,
then passes the ReadOnlySpan<T> to the provided action, along with the argument.
public void ConvertToText<T>(double value, T argument, ReadOnlySpanAction<char, T> action)
Parameters
valuedoubleThe number to convert.
argumentTThe argument to pass into the
action.actionReadOnlySpanAction<char, T>The action to perform with the resulting ReadOnlySpan<T> of characters.
Type Parameters
TThe type of
argumentto pass into theaction.
Exceptions
- ArgumentNullException
Thrown if
actionis null.
ConvertToText<T>(double, T, ReadOnlySpanAction<char, T>, FloatFormatInfo)
Converts a double-precision floating-point number into a Span<T> of characters.
public void ConvertToText<T>(double value, T argument, ReadOnlySpanAction<char, T> action, FloatFormatInfo format)
Parameters
valuedoubleThe number to convert.
argumentTThe argument to pass into the
action.actionReadOnlySpanAction<char, T>The action to perform with the resulting ReadOnlySpan<T> of characters.
formatFloatFormatInfoInformation used to the format of the result.
Type Parameters
TThe type of
argumentto pass into theaction.
Exceptions
- ArgumentNullException
Thrown if
actionis null.
ConvertToText<T>(double, T, ReadOnlySpanAction<char, T>, int)
Converts a double-precision floating-point number into a Span<T> of characters,
then passes the ReadOnlySpan<T> to the provided action, along with the argument.
public void ConvertToText<T>(double value, T argument, ReadOnlySpanAction<char, T> action, int minFractionalDigits)
Parameters
valuedoubleThe number to convert.
argumentTThe argument to pass into the
action.actionReadOnlySpanAction<char, T>The action to perform with the resulting ReadOnlySpan<T> of characters.
minFractionalDigitsintThe minimum number of fractional digits to display.
Type Parameters
TThe type of
argumentto pass into theaction.
Exceptions
- ArgumentNullException
Thrown if
actionis null.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsis less than zero.
ConvertToText<T>(double, T, ReadOnlySpanAction<char, T>, int, int)
Converts a double-precision floating-point number into a Span<T> of characters,
then passes the ReadOnlySpan<T> to the provided action, along with the argument.
public void ConvertToText<T>(double value, T argument, ReadOnlySpanAction<char, T> action, int minFractionalDigits, int maxFractionalDigits)
Parameters
valuedoubleThe number to convert.
argumentTThe argument to pass into the
action.actionReadOnlySpanAction<char, T>The action to perform with the resulting ReadOnlySpan<T> of characters.
minFractionalDigitsintThe minimum number of fractional digits to display.
maxFractionalDigitsintThe maximum number of fractional digits to display.
Type Parameters
TThe type of
argumentto pass into theaction.
Exceptions
- ArgumentNullException
Thrown if
actionis null.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsormaxFractionalDigitsare less than zero, or ifminFractionalDigitsis greater thanmaxFractionalDigits.
ConvertToText<T>(double, T, ReadOnlySpanAction<char, T>, int, int, bool)
Converts a double-precision floating-point number into a Span<T> of characters,
then passes the ReadOnlySpan<T> to the provided action, along with the argument.
public void ConvertToText<T>(double value, T argument, ReadOnlySpanAction<char, T> action, int minFractionalDigits, int maxFractionalDigits, bool groupDigits)
Parameters
valuedoubleThe number to convert.
argumentTThe argument to pass into the
action.actionReadOnlySpanAction<char, T>The action to perform with the resulting ReadOnlySpan<T> of characters.
minFractionalDigitsintThe minimum number of fractional digits to display.
maxFractionalDigitsintThe maximum number of fractional digits to display.
groupDigitsboolThe maximum number of fractional digits to display.
Type Parameters
TThe type of
argumentto pass into theaction.
Exceptions
- ArgumentNullException
Thrown if
actionis null.- ArgumentOutOfRangeException
Thrown if
minFractionalDigitsormaxFractionalDigitsare less than zero, or ifminFractionalDigitsis greater thanmaxFractionalDigits.