gcvt(3)

πŸ’– gcvt(3) β€” the "float goes in, string comes out" page πŸ’–

okay so bestie, you found the gcvt page in the Library Functions Manual and honestly? this one is a little vintage. it's giving my grandma's encyclopaedia but make it C. let's get into it 🫢


✨ NAME ✨

gcvt β€” convert a floating-point number to a string

no fr that's literally it, that's the whole job πŸ’…


🌸 LIBRARY 🌸

Standard C library (libc, -lc)


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>

char *gcvt(double number, int ndigit, char *buf);

✨ Feature Test Macro Requirements for glibc (see feature_test_macros(7)): ✨

gcvt():

  • Since glibc 2.17:
(_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200809L))
    || /* glibc >= 2.20 */ _DEFAULT_SOURCE
    || /* glibc <= 2.19 */ _SVID_SOURCE
  • glibc 2.12 to glibc 2.16:
(_XOPEN_SOURCE >= 500 && ! (_POSIX_C_SOURCE >= 200112L))
    || _SVID_SOURCE
  • Before glibc 2.12:
_SVID_SOURCE || _XOPEN_SOURCE >= 500

bestie the way these macros gatekeep 😭 like okay girl, define your feature test macros or she's simply not showing up. copy them exactly, no cap, one wrong character and the compiler gets an attitude.


πŸ¦‹ DESCRIPTION πŸ¦‹

So gcvt() takes your number, glows it up, and converts it into a minimal length null-terminated ASCII string, then tucks that result into buf. iconic behaviour honestly.

And she's picky about significant digits: it produces ndigit significant digits, and it'll pick either printf(3) F format or E format for the fit. it decides. you don't. main character energy for real πŸ”₯


⭐ RETURN VALUE ⭐

gcvt() returns buf. that's it. that's the whole return value. she hands you back the thing you gave her, now with a cute string in it πŸ’œ


πŸ’… ATTRIBUTES πŸ’…

For an explanation of the terms used in this section, see attributes(7).

  • gcvt() β€” Thread safety: MT-Safe

(vibe check: passed, she's thread-safe, go off queen πŸ‘‘)


🌈 STANDARDS 🌈

None.

not a single one. she's unstandardised, she's free, she's ✨unbothered✨. periodt.


πŸ“ HISTORY πŸ“

  • Marked as LEGACY in POSIX.1-2001.
  • POSIX.1-2008 removed it, recommending the use of sprintf(3) instead (though snprintf(3) may be preferable).
okay so real talk bestie: if you're writing new code, maybe don't reach for this one 😭 she's legacy-coded. the manual literally says use sprintf(3) instead, and side-eyes it by noting snprintf(3) may be preferable. do with that information what you will 🫢

🧚 SEE ALSO 🧚


and that's the page!! go forth and convert your floats, bestie πŸ’–βœ¨

this chaotic lil rewrite came from the Linux man-pages 6.20 release, dated 2026-02-08 β€” original gcvt(3) page, now serving looks in lowercase πŸŽ€

πŸ“¦ 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