Table of Contents

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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is 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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

format FloatFormatInfo

Information used to the format of the result.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is 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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

format FloatFormatInfo

Information used to the format of the result.

valueIsNegative bool

The value will be true if the value is a negative number.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is 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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

minFractionalDigits int

The minimum number of fractional digits to display.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is not long enough to hold the value.

ArgumentOutOfRangeException

Thrown if minFractionalDigits is 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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

minFractionalDigits int

The minimum number of fractional digits to display.

maxFractionalDigits int

The maximum number of fractional digits to display.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is not long enough to hold the value.

ArgumentOutOfRangeException

Thrown if minFractionalDigits or maxFractionalDigits are less than zero, or if minFractionalDigits is greater than maxFractionalDigits.

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

value double

The number to convert.

result Span<char>

The target to contain the result of the conversion.

minFractionalDigits int

The minimum number of fractional digits to display.

maxFractionalDigits int

The maximum number of fractional digits to display.

groupDigits bool

The maximum number of fractional digits to display.

Returns

int

Returns the number of characters in the result.

Exceptions

IndexOutOfRangeException

Thrown if result is not long enough to hold the value.

ArgumentOutOfRangeException

Thrown if minFractionalDigits or maxFractionalDigits are less than zero, or if minFractionalDigits is greater than maxFractionalDigits.

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

value double

The number to convert.

argument T

The argument to pass into the action.

action ReadOnlySpanAction<char, T>

The action to perform with the resulting ReadOnlySpan<T> of characters.

Type Parameters

T

The type of argument to pass into the action.

Exceptions

ArgumentNullException

Thrown if action is 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

value double

The number to convert.

argument T

The argument to pass into the action.

action ReadOnlySpanAction<char, T>

The action to perform with the resulting ReadOnlySpan<T> of characters.

format FloatFormatInfo

Information used to the format of the result.

Type Parameters

T

The type of argument to pass into the action.

Exceptions

ArgumentNullException

Thrown if action is 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

value double

The number to convert.

argument T

The argument to pass into the action.

action ReadOnlySpanAction<char, T>

The action to perform with the resulting ReadOnlySpan<T> of characters.

minFractionalDigits int

The minimum number of fractional digits to display.

Type Parameters

T

The type of argument to pass into the action.

Exceptions

ArgumentNullException

Thrown if action is null.

ArgumentOutOfRangeException

Thrown if minFractionalDigits is 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

value double

The number to convert.

argument T

The argument to pass into the action.

action ReadOnlySpanAction<char, T>

The action to perform with the resulting ReadOnlySpan<T> of characters.

minFractionalDigits int

The minimum number of fractional digits to display.

maxFractionalDigits int

The maximum number of fractional digits to display.

Type Parameters

T

The type of argument to pass into the action.

Exceptions

ArgumentNullException

Thrown if action is null.

ArgumentOutOfRangeException

Thrown if minFractionalDigits or maxFractionalDigits are less than zero, or if minFractionalDigits is greater than maxFractionalDigits.

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

value double

The number to convert.

argument T

The argument to pass into the action.

action ReadOnlySpanAction<char, T>

The action to perform with the resulting ReadOnlySpan<T> of characters.

minFractionalDigits int

The minimum number of fractional digits to display.

maxFractionalDigits int

The maximum number of fractional digits to display.

groupDigits bool

The maximum number of fractional digits to display.

Type Parameters

T

The type of argument to pass into the action.

Exceptions

ArgumentNullException

Thrown if action is null.

ArgumentOutOfRangeException

Thrown if minFractionalDigits or maxFractionalDigits are less than zero, or if minFractionalDigits is greater than maxFractionalDigits.