| 359 | } |
| 360 | |
| 361 | int |
| 362 | dectoasc(decimal *np, char *cp, int len, int right) |
| 363 | { |
| 364 | char *str; |
| 365 | numeric *nres; |
| 366 | |
| 367 | rsetnull(CSTRINGTYPE, (char *) cp); |
| 368 | if (risnull(CDECIMALTYPE, (char *) np)) |
| 369 | return 0; |
| 370 | |
| 371 | nres = PGTYPESnumeric_new(); |
| 372 | if (nres == NULL) |
| 373 | return ECPG_INFORMIX_OUT_OF_MEMORY; |
| 374 | |
| 375 | if (PGTYPESnumeric_from_decimal(np, nres) != 0) |
| 376 | { |
| 377 | PGTYPESnumeric_free(nres); |
| 378 | return ECPG_INFORMIX_OUT_OF_MEMORY; |
| 379 | } |
| 380 | |
| 381 | if (right >= 0) |
| 382 | str = PGTYPESnumeric_to_asc(nres, right); |
| 383 | else |
| 384 | str = PGTYPESnumeric_to_asc(nres, nres->dscale); |
| 385 | |
| 386 | PGTYPESnumeric_free(nres); |
| 387 | if (!str) |
| 388 | return -1; |
| 389 | |
| 390 | /* |
| 391 | * TODO: have to take care of len here and create exponential notation if |
| 392 | * necessary |
| 393 | */ |
| 394 | if ((int) (strlen(str) + 1) > len) |
| 395 | { |
| 396 | if (len > 1) |
| 397 | { |
| 398 | cp[0] = '*'; |
| 399 | cp[1] = '\0'; |
| 400 | } |
| 401 | free(str); |
| 402 | return -1; |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | strcpy(cp, str); |
| 407 | free(str); |
| 408 | return 0; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | int |
| 413 | dectodbl(decimal *np, double *dblp) |