 |
INFORMIX-ESQL/C Programmer's Manual ESQL/C Function Library |
|
dectoasc()
The dectoasc() function converts a decimal type number to a C char type value.
Syntax
Usage
If right = -1, the decimal value of *np determines the number of decimal places.
If the decimal number does not fit into a character string of length len, dectoasc() converts the number to an exponential notation. If the number still does not fit, dectoasc() fills the string with asterisks. If the number is shorter than the string, dectoasc() left-justifies the number and pads it on the right with blanks.
Because the character string that dectoasc() returns is not null terminated, your program must add a null character to the string before you print it.
Return Codes
Example
The file dectoasc.ec in the demo directory contains the following sample program.
/*
* dectoasc.ec *
The following program converts DECIMAL numbers to strings of varying sizes.
*/
#include <stdio.h>
EXEC SQL include decimal;
#define END sizeof(result)
char string1[] = "-12345.038782";
char string2[] = "480";
char result[40];
main()
{
mint x;
dec_t num1, num2;
printf("DECTOASC Sample ESQL Program running.\n\n");
printf("String Decimal Value 1 = %s\n", string1);
if (x = deccvasc(string1, strlen(string1), &num1))
{
printf("Error %d in converting string1 to DECIMAL\n", x);
exit(1);
}
printf("String Decimal Value 2 = %s\n", string2);
if (x = deccvasc(string2, strlen(string2), &num2))
{
printf("Error %d in converting string2 to DECIMAL\n", x);
exit(1);
}
printf("\nConverting Decimal back to ASCII\n");
printf(" Executing: dectoasc(&num1, result, 5, -1)\n");
if (x = dectoasc(&num1, result, 5, -1))
printf("\tError %d in converting DECIMAL1 to string\n", x);
else
{
result[5] = '\0'; /* null terminate */
printf("\tResult ='%s'\n", result);
}
printf("Executing: dectoasc(&num1, result, 10, -1)\n");
if (x = dectoasc(&num1, result, 10, -1))
printf("Error %d in converting DECIMAL1 to string\n", x);
else
{
result[10] = '\0'; /* null terminate */
printf("\tResult = '%s'\n", result);
}
printf("Executing: dectoasc(&num2, result, END, 3)\n");
if (x = dectoasc(&num2, result, END, 3))
printf("\tError %d in converting DECIMAL2 to string\n", x);
else
{
result[END-1] = '\0'; /* null terminate */
printf("\tResult = '%s'\n", result);
}
printf("\nDECTOASC Sample Program over.\n\n")
}
Output
INFORMIX-ESQL/C Programmer's Manual, Version 9.21
Copyright © 1999, Informix Software, Inc. All rights reserved