The rfmtlong() function
The rfmtlong() function uses a formatting mask to convert a C long value to a character string.
Syntax
mint rfmtlong(lng_val, fmtstring, outbuf)
int4 lng_val;
char *fmtstring;
char *outbuf;
- lng_val
- The int4 integer that rfmtlong() converts to character value.
- fmtstring
- A pointer to a character buffer that contains the formatting mask for the value in lng_val.
- outbuf
- A pointer to a character buffer that receives the formatted string for the value in lng_val.
Usage
The fmtstring argument of the rfmtlong() function points to the numeric-formatting mask, which contains characters that describe how to format the long integer value. For more information about these formatting characters, see Format numeric strings.
When you use rfmtlong() to format MONEY values, the function uses the currency symbols that the DBMONEY environment variable specifies. If you do not set this environment variable, rfmtlong() 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 IBM® Informix Guide to SQL: Reference.)
When you use a nondefault locale that has a multibyte code set, rfmtlong() supports multibyte characters in the format string. For more information, see the IBM 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
/*
* rfmtlong.ec *
The following program applies a series of format specifications to a series
of longs and displays the result of each format.
*/
#include <stdio.h>
long lngs[] =
{
21020304,
334899312,
-334899312,
-12344455,
0
};
char *formats[] =
{
"################",
"$$$$$$$$$$$$$.##",
"(&,&&&,&&&,&&&.)",
"<<<<,<<<,<<<,<<<",
"$************.**",
0
};
char result[41];
main()
{
mint x;
mint s = 0, f;
printf("RFMTLONG Sample ESQL Program running.\n\n");
while(lngs[s]) /* for each long in lngs[] */
{
printf("Long Number = %d\n", lngs[s]);
f = 0;
while(formats[f]) /* format with each of formats[] */
{
if (x = rfmtlong(lngs[s], formats[f], result))
{
printf("Error %d in formatting %d using %s.\n",
x, lngs[s], formats[f]);
break;
}
/*
* Display result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++s; /* bump to next long */
printf("\n"); /* separate display groups */
}
printf("\nRFMTLONG Sample Program over.\n\n");
}
Output
RFMTLONG ESQL Sample Program running.
Long Number = 21020304
Format String = '################' Result = ' 21020304'
Format String = '$$$$$$$$$$$$$.##' Result = ' $21020304.00'
Format String = '(&,&&&,&&&,&&&.)' Result = ' 00021,020,304. '
Format String = '<<<<,<<<,<<<,<<<' Result = '21,020,304'
Format String = '$************.**' Result = '$****21020304.00'
Long Number = 334899312
Format String = '################' Result = ' 334899312'
Format String = '$$$$$$$$$$$$$.##' Result = ' $334899312.00'
Format String = '(&,&&&,&&&,&&&.)' Result = ' 00334,899,312. '
Format String = '<<<<,<<<,<<<,<<<' Result = '334,899,312'
Format String = '$************.**' Result = '$***334899312.00'
Long Number = -334899312
Format String = '################' Result = ' 334899312'
Format String = '$$$$$$$$$$$$$.##' Result = ' $334899312.00'
Format String = '(&,&&&,&&&,&&&.)' Result = '(00334,899,312.)'
Format String = '<<<<,<<<,<<<,<<<' Result = '334,899,312'
Format String = '$************.**' Result = '$***334899312.00'
Long Number = -12344455
Format String = '################' Result = ' 12344455'
Format String = '$$$$$$$$$$$$$.##' Result = ' $12344455.00'
Format String = '(&,&&&,&&&,&&&.)' Result = '(00012,344,455.)'
Format String = '<<<<,<<<,<<<,<<<' Result = '12,344,455'
Format String = '$************.**' Result = ' $****12344455.00'
RFMTLONG Sample Program over.