The deccvflt() function
The deccvflt() function converts a C float type number into an ESQL/C decimal type number.
Syntax
int deccvflt(flt_val, dec_val)
float flt_val;
dec_t *dec_val;
- flt_val
- The float value that deccvflt() converts to a decimal type value.
- dec_val
- A pointer to a decimal structure where deccvflt() places the result of the conversion.
Return codes
- 0
- The conversion was successful.
- <0
- The conversion failed.
Example
The following example program converts two
float type numbers to DECIMAL numbers and displays the results.
#include <stdio.h>
EXEC SQL include decimal;
char result[41];
main()
{
int x;
dec_t num;
float f = 2147483674;
printf(“DECCVFLT Sample ESQL Program Running.\n\n);
if (x = deccvflt((float)1234.5678901234, &num))
{
printf(“Error %d in converting double1 to DECIMAL\n”, x);
exit(1);
}
if (x = dectoasc(&num, result, sizeof(result), -1))
{
printf(“Error %d in converting DECIMAL1 to string\n”, x);
exit(1);
}
result[40] = ‘\0’;
printf(“ String Value = %s\n”, result);
printf(“ Number 2 (float) = %.1f\n”, f);
if (x = deccvflt(f, &num))
{
printf(“Error %d in converting float2 to DECIMAL\n”, x);
exit(1);
}
if (x = dectoasc(&num, result, sizeof(result), -1))
{
printf(“Error %d in converting DECIMAL2 to string\n”, x);
exit(1);
}
result[40] = ‘\0’;
printf(“ String Value = %s\n”, result);
printf(“\n DECCVFLT Sample Program Over.\n\n”);
exit(0);
}
Output
DECCVFLT Sample ESQL Program running.
Number 1 (float) = 1234.5678901234
String Value = 1234.56787
Number 2 (float) = 2147483647.0
String Value = 2147483647.0
DECCVFLT Sample Program over.