INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 5: Working with Numeric Data Types
Home Contents Index Master Index New Book

Numeric-Formatting Functions

INFORMIX-ESQL/C provides special functions that allow you to format numeric expressions. These formatting functions apply a given formatting mask to a numeric value to allow you to line up decimal points, right- or left-justify the number, enclose a negative number in parentheses, and so on. The ESQL/C library includes the following functions that support formatting masks for numeric values.

Function Name Description

rfmtdec()

Converts a decimal value to a string

rfmtdouble()

Converts a double value to a string

rfmtlong()

Converts a long integer value to a string

When you compile your ESQL/C program with the esql command, the preprocessor automatically links these functions to your program.

This chapter describes the characters that you can use to create a formatting mask. It also provides extensive examples that show the results of applying these masks to numeric values.

rfmtdec()

The rfmtdec() function uses a formatting mask to convert a decimal value to a character string.

Syntax

Usage

The fmtstring argument of the rfmtdec() function points to the numeric-formatting mask, which contains characters that describe how to format the decimal value. For more information on these formatting characters, see "Formatting Numeric Strings".

GLS
When you use rfmtdec() to format MONEY values, the function uses the currency symbols that the DBMONEY environment variable specifies. If you do not set this environment variable, rfmtdec() uses the currency symbols that the client locale defines. The default locale, U.S. English, defines currency symbols as if you set DBMONEY to "$,.". (For a discussion of DBMONEY, see the
Informix Guide to SQL: Reference).

When you use a nondefault locale that has a multibyte code set, rfmtdec() supports multibyte characters in the format string. For more information, see the Informix Guide to GLS Functionality.

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

The demo directory contains this sample program in the file rfmtdec.ec.

Example Output

rfmtdouble()

The rfmtdouble() function uses a formatting mask to convert a double value to a character string.

Syntax

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 on these formatting characters, see "Formatting Numeric Strings".

GLS
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, U.S. English, defines currency symbols as if you set DBMONEY to "$,.". (For a discussion of DBMONEY, see the
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 Informix Guide to GLS Functionality.

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

The demo directory contains this sample program in the file rfmtdouble.ec.

Example Output

rfmtlong()

The rfmtlong() function uses a formatting mask to convert a C long value to a character string.

Syntax

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 on these formatting characters, see "Formatting Numeric Strings".

GLS
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, U.S. English, defines currency symbols as if you set DBMONEY to "$,.". (For a discussion of DBMONEY, see the
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 Informix Guide to GLS Functionality.

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

The demo directory contains this sample program in the file rfmtlong.ec.

Example Output




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.