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 (thoughsnprintf(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 usesprintf(3)instead, and side-eyes it by notingsnprintf(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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms