strfromd(3)

✨ strfromd β€” string from float ✨

okay bestie, this is strfromd(3) from the library functions manual and it's literally about turning float values into strings πŸ’–


🌸 NAME 🌸

strfromd, strfromf, strfroml β€” string from float

πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)

🫢 SYNOPSIS 🫢

#include <stdlib.h>

int strfromd(size_t n;
             char str[restrict n], size_t n,
             const char *restrict format, double fp);
int strfromf(size_t n;
             char str[restrict n], size_t n,
             const char *restrict format, float fp);
int strfroml(size_t n;
             char str[restrict n], size_t n,
             const char *restrict format, long double fp);

πŸŽ€ Feature Test Macro Requirements for glibc (see feature_test_macros(7)) πŸŽ€

  • strfromd(), strfromf(), strfroml():
    • __STDC_WANT_IEC_60559_BFP_EXT__

πŸ’… DESCRIPTION πŸ’…

so these functions take a floating-point value, fp, and convert it into a string of characters, str, with a format string you get to configure. At most n characters are stored into str.

The terminating null byte ('\0') is written if and only if n is sufficiently large β€” otherwise the written string is truncated at n characters. no cap, that's just how it is 🫠

The strfromd(), strfromf(), and strfroml() functions are equivalent to

snprintf(str, n, format, fp);

except for the format string.

✨ Format of the format string ✨

The format string must start with the character '%'. This is followed by an optional precision which starts with the period character (.), followed by an optional decimal integer. If no integer is specified after the period character, a precision of zero is used. Finally, the format string should have one of the conversion specifiers a, A, e, E, f, F, g, or G.

The conversion specifier is applied based on the floating-point type indicated by the function suffix. Therefore, unlike snprintf(), the format string does not have a length modifier character. See snprintf(3) for a detailed description of these conversion specifiers.

The implementation conforms to the C99 standard on conversion of NaN and infinity values:

If fp is a NaN, +NaN, or -NaN, and f (or a, e, g) is the conversion specifier, the conversion is to "nan", "nan", or "-nan", respectively. If F (or A, E, G) is the conversion specifier, the conversion is to "NAN" or "-NAN".
Likewise if fp is infinity, it is converted to [-]inf or [-]INF.

A malformed format string results in undefined behavior. πŸ’€ like literally do not.

πŸ‘‘ RETURN VALUE πŸ‘‘

The strfromd(), strfromf(), and strfroml() functions return the number of characters that would have been written in str if n had enough space, not counting the terminating null byte. So if you get a return value of n or greater, that means the output was truncated. 😭 bestie got clipped.

🌈 ATTRIBUTES 🌈

For an explanation of the terms used in this section, see attributes(7) and the POSIX Safety Concepts section in GNU C Library manual.

  • Interface strfromd(), strfromf(), strfroml():
    • Thread safety: MT-Safe locale
    • Async-signal safety: AS-Unsafe heap
    • Async-cancel safety: AC-Unsafe mem
Note: these attributes are preliminary.

⭐ STANDARDS ⭐

ISO/IEC TS 18661-1.

πŸ¦‹ VERSIONS πŸ¦‹

  • strfromd()
  • strfromf()
  • strfroml()

glibc 2.25.

πŸ“ NOTES πŸ“

These functions take account of the LC_NUMERIC category of the current locale. yes she's locale-aware, she's that girl πŸ’

🧚 EXAMPLES 🧚

To convert the value 12.1 as a float type to a string using decimal notation, resulting in "12.100000":

#define __STDC_WANT_IEC_60559_BFP_EXT__
#include <stdlib.h>
int ssize = 10;
char s[ssize];
strfromf(s, ssize, "%f", 12.1);

To convert the value 12.3456 as a float type to a string using decimal notation with two digits of precision, resulting in "12.35":

#define __STDC_WANT_IEC_60559_BFP_EXT__
#include <stdlib.h>
int ssize = 10;
char s[ssize];
strfromf(s, ssize, "%.2f", 12.3456);

To convert the value 12.345e19 as a double type to a string using scientific notation with zero digits of precision, resulting in "1E+20":

#define __STDC_WANT_IEC_60559_BFP_EXT__
#include <stdlib.h>
int ssize = 10;
char s[ssize];
strfromd(s, ssize, "%.E", 12.345e19);

πŸ’œ SEE ALSO πŸ’œ

atof(3), snprintf(3), strtod(3)


and that's the whole page bestie 🫢 this run was brought to you by Linux man-pages 6.20, dated 2026-07-26, for the strfromd(3) girlies ✨ mwah, go format some floats πŸ’…πŸ’–

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms