Next: , Previous: , Up: Arithmetic Functions   [Contents][Index]


20.12 Printing of Floats

The ‘strfrom’ functions are declared in stdlib.h.

Function: int strfromd (char *restrict string, size_t size, const char *restrict format, double value)
Function: int strfromf (char *restrict string, size_t size, const char *restrict format, float value)
Function: int strfroml (char *restrict string, size_t size, const char *restrict format, long double value)

Preliminary: | MT-Safe locale | AS-Unsafe heap | AC-Unsafe mem | See POSIX Safety Concepts.

The functions strfromd (“string-from-double”), strfromf (“string-from-float”), and strfroml (“string-from-long-double”) convert the floating-point number value to a string of characters and stores them into the area pointed to by string. The conversion writes at most size characters and respects the format specified by format.

The format string must start with the character ‘%’. An optional precision follows, which starts with a period, ‘.’, and may be followed by a decimal integer, representing the precision. If a decimal integer is not specified after the period, the precision is taken to be zero. The character ‘*’ is not allowed. Finally, the format string ends with one of the following conversion specifiers: ‘a’, ‘A’, ‘e’, ‘E’, ‘f’, ‘F’, ‘g’ or ‘G’ (see Table of Output Conversions). Invalid format strings result in undefined behavior.

These functions return the number of characters that would have been written to string had size been sufficiently large, not counting the terminating null character. Thus, the null-terminated output has been completely written if and only if the returned value is less than size.

These functions were introduced by ISO/IEC TS 18661-1.

Function: int strfromfN (char *restrict string, size_t size, const char *restrict format, _FloatN value)
Function: int strfromfNx (char *restrict string, size_t size, const char *restrict format, _FloatNx value)

Preliminary: | MT-Safe locale | AS-Unsafe heap | AC-Unsafe mem | See POSIX Safety Concepts.

These functions are like strfromd, except for the type of value.

They were introduced in ISO/IEC TS 18661-3 and are available on machines that support the related types; see Mathematics.


Next: Old-fashioned System V number-to-string functions, Previous: Parsing of Numbers, Up: Arithmetic Functions   [Contents][Index]