Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


strfromd(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ATTRIBUTES |STANDARDS |VERSIONS |NOTES |EXAMPLES |SEE ALSO |COLOPHON

strfromd(3)              Library Functions Manualstrfromd(3)

NAME        top

       strfromd, strfromf, strfroml - convert a floating-point value into       a string

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <stdlib.h>int strfromd(size_t n;charstr[restrictn], size_tn,const char *restrictformat, doublefp);int strfromf(size_t n;charstr[restrictn], size_tn,const char *restrictformat, floatfp);int strfroml(size_t n;charstr[restrictn], size_tn,const char *restrictformat, long doublefp);   Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):strfromd(),strfromf(),strfroml():           __STDC_WANT_IEC_60559_BFP_EXT__

DESCRIPTION        top

       These functions convert a floating-point value,fp, into a string       of characters,str, with a configurableformat string.  At mostn       characters are stored intostr.       The terminating null byte ('\0') is written if and only ifn is       sufficiently large, otherwise the written string is truncated atn       characters.       Thestrfromd(),strfromf(), andstrfroml() functions are       equivalent to           snprintf(str, n, format, fp);       except for theformat string.Format of the format string       Theformat 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 specifiersa,A,e,E,f,F,g, orG.       The conversion specifier is applied based on the floating-point       type indicated by the function suffix.  Therefore, unlikesnprintf(), the format string does not have a length modifier       character.  Seesnprintf(3) for a detailed description of these       conversion specifiers.       The implementation conforms to the C99 standard on conversion of       NaN and infinity values:              Iffp is a NaN, +NaN, or -NaN, andf(ora,e,g) is the              conversion specifier, the conversion is to "nan", "nan", or              "-nan", respectively.  IfF(orA,E,G) is the conversion              specifier, the conversion is to "NAN" or "-NAN".              Likewise iffp is infinity, it is converted to [-]inf or              [-]INF.       A malformedformat string results in undefined behavior.

RETURN VALUE        top

       Thestrfromd(),strfromf(), andstrfroml() functions return the       number of characters that would have been written instr ifn had       enough space, not counting the terminating null byte.  Thus, a       return value ofn or greater means that the output was truncated.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7) and thePOSIX Safety Conceptssection in GNU C       Library manual.       ┌─────────────────────────┬─────────────────────┬────────────────┐       │InterfaceAttributeValue│       ├─────────────────────────┼─────────────────────┼────────────────┤       │                         │ Thread safety       │ MT-Safe locale │       │strfromd(),strfromf(), ├─────────────────────┼────────────────┤       │strfroml()              │ Async-signal safety │ AS-Unsafe heap │       │                         ├─────────────────────┼────────────────┤       │                         │ Async-cancel safety │ AC-Unsafe mem  │       └─────────────────────────┴─────────────────────┴────────────────┘       Note: these attributes are preliminary.

STANDARDS        top

       ISO/IEC TS 18661-1.

VERSIONS        top

strfromd()strfromf()strfroml()              glibc 2.25.

NOTES        top

       These functions take account of theLC_NUMERICcategory of the       current locale.

EXAMPLES        top

       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        top

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

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-06-28strfromd(3)

Pages that refer to this page:atof(3)printf(3)strtod(3)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp