Skip to content

ST::float_formatter

Michael Hansen edited this page Nov 22, 2019 · 3 revisions

ST::float_formatter<float_T>

Since string_theory 3.0.

Headers

#include <string_theory/format_numeric>

Template Parameters

Type Description
float_T Numeric type for formatting. This must be a floating point type.

Public Functions

Name Summary
(constructor) ST::float_formatter constructor
format Format a floating point value
text Retrieve a pointer to the formatted text
size Retrieve the size of the formatted text

Details

ST::float_formatter is a helper class for fast conversion of floating point values to 7-bit ASCII text, analogous to ST::uint_formatter for unsigned integer types. This is used internally by ST::string, but the implementation used by ST::format is more sophisticated.

Implementation detail The formatting is currently performed by a call to snprintf with a restricted set of format parameters. For more control over floating point formatting, consider using ST::format instead.

Member Documentation

ST::float_formatter constructor

Signature
float_formatter() noexcept

Constructs an empty float_formatter.

Since string_theory 3.0.


ST::float_formatter::format

Signature
void format(float_T value, char format) noexcept

Format the specified floating point value into this formatter object's internal buffer.

The only supported format characters are e, f, g, E, F, and G, which have the same meaning as in snprintf().

Since string_theory 3.0.


ST::float_formatter::size

Signature
size_t size() const noexcept

For float_formatter objects which contain a formatted value, this returns the number of characters in the formatted text.

Calling size() on an empty float_formatter (i.e. before format() has been called) is undefined behavior.

Since string_theory 3.0.

See also text()


ST::float_formatter::text

Signature
const char *text() const noexcept

For float_formatter objects which contain a formatted value, this returns a pointer to the beginning of the formatted text.

Calling text() on an empty float_formatter will return an empty string.

Since string_theory 3.0.

See also size()