/*
 * CM_FMT_AMT.pgc - cm 모듈 서비스 CM_FMT_AMT (one service = one file).
 * Split out of the former inline cm_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by cm_svr at tpsvrinit.
 */
#include "CM_FMT_AMT.h"

/* 17. CM_FMT_AMT - 금액 천단위 콤마 포맷 (순수 계산). */
void CM_FMT_AMT(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char raw[32], out[48];
    long amt = getl(b, T_AMOUNT);
    int n, i, j, k, neg = 0;
    if (amt < 0) { neg = 1; amt = -amt; }
    sprintf(raw, "%ld", amt);
    n = (int)strlen(raw);
    j = 0;
    if (neg) out[j++] = '-';
    for (i = 0; i < n; i++) {
        out[j++] = raw[i];
        k = n - i - 1;
        if (k > 0 && k % 3 == 0) out[j++] = ',';
    }
    out[j] = 0;
    sets_(b, T_STR4, out);
    OK(b);
}
