The rfmtdouble() function
The rfmtdouble() function uses a formatting mask to convert a double value to a character string.
Syntax
mint rfmtdouble(dbl_val, fmtstring, outbuf)
double dbl_val;
char *fmtstring;
char *outbuf;
- dbl_val
- The double number to format.
- fmtstring
- A pointer to a character buffer that contains the formatting mask for the value in dbl_val.
- outbuf
- A pointer to a character buffer that receives the formatted string for the value in dbl_val.
Usage
The fmtstring argument of the rfmtdouble() function points to the numeric-formatting mask, which contains characters that describe how to format the double value. For more information about these formatting characters, see Format numeric strings.
When you use rfmtdouble() to format MONEY values, the function uses the currency symbols that the DBMONEY environment variable specifies. If you do not set this environment variable, rfmtdouble() uses the currency symbols that the client locale defines. The default locale, US English, defines currency symbols as if you set DBMONEY to “$,.”. (For a discussion of DBMONEY, see the HCL Informix Guide to SQL: Reference.)
When you use a nondefault locale that has a multibyte code set, rfmtdouble() supports multibyte characters in the format string. For more information, see the HCL Informix GLS User's Guide.
Return codes
- 0
- The conversion was successful.
- -1211
- The program ran out of memory (memory-allocation error).
- -1217
- The format string is too large.
Example
/*
* rfmtdouble.ec *
The following program applies a series of format specifications to a
series of doubles and displays the result of each format.
*/
#include <stdio.h>
double dbls[] =
{
210203.204,
4894,
443.334899312,
-12344455,
0
};
char *formats[] =
{
"#############",
"<,<<<,<<<,<<<",
"$$$$$$$$$$.##",
"(&&,&&&,&&&.)",
"$*********.**",
0
};
char result[41];
main()
{
mint x;
mint i = 0, f;
printf("RFMTDOUBLE Sample ESQL Program running.\n\n");
while(dbls[i]) /* for each number in dbls */
{
printf("Double Number = %g\n", dbls[i]);
f = 0;
while(formats[f]) /* format with each of formats[] */
{
if (x = rfmtdouble(dbls[i], formats[f], result))
{
printf("Error %d in formatting %g using %s\n",
x, dbls[i], formats[f]);
break;
}
/*
* Display each result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++i; /* bump to next double */
printf("\n"); /* separate result groups */
}
printf("\nRFMTDOUBLE Sample Program over.\n\n");
}
Output
RFMTDOUBLE Sample ESQL Program running.
Double Number = 210203
Format String = '#############' Result = ' 210203'
Format String = '<,<<<,<<<,<<<' Result = '210,203'
Format String = '$$$$$$$$$$.##' Result = ' $210203.20'
Format String = '(&&,&&&,&&&.)' Result = ' 000210,203. '
Format String = '$*********.**' Result = '$***210203.20'
Double Number = 4894
Format String = '#############' Result = ' 4894'
Format String = '<,<<<,<<<,<<<' Result = '4,894'
Format String = '$$$$$$$$$$.##' Result = ' $4894.00'
Format String = '(&&,&&&,&&&.)' Result = ' 000004,894. '
Format String = '$*********.**' Result = '$*****4894.00'
Double Number = 443.335
Format String = '#############' Result = ' 443'
Format String = '<,<<<,<<<,<<<' Result = '443'
Format String = '$$$$$$$$$$.##' Result = ' $443.33'
Format String = '(&&,&&&,&&&.)' Result = ' 0000000443. '
Format String = '$*********.**' Result = '$******443.33'
Double Number = -1.23445e+07
Format String = '#############' Result = ' 12344455'
Format String = '<,<<<,<<<,<<<' Result = '12,344,455'
Format String = '$$$$$$$$$$.##' Result = ' $12344455.00'
Format String = '(&&,&&&,&&&.)' Result = '(12,344,455.)'
Format String = '$*********.**' Result = '$*12344455.00'
RFMTDOUBLE Sample Program over.