金额字段加千位分隔符

/*========================================================================
=给金额字段加千位分隔符                                                  =
========================================================================*/
char * PAddFloatComma(double dIn, char *sOut)
{
    int i, j, iLen, iPreLen;
    char    sBuf[20];
    unsigned char cNgFg;    /* Negative flag */

    PLog1(__FILE__, __LINE__, "dIn[%lf]",dIn);
    if(-0.001 < dIn && dIn < 0.001)
    {
        sOut[0] = '0';
        sOut[1] = '.';
        sOut[2] = '0';
        sOut[3] = '0';
        sOut[4] = 0;
        return sOut;
    }
    if(dIn > 999999999999999.99 || dIn < -999999999999999.99)
    {
        return NULL;
    }

    if(dIn < -0.001)
    {
        cNgFg = 1;          /* set negative flag */
    }
    else
    {
        cNgFg = 0;
    }
    sprintf(sBuf, "%-15.2f", dIn);  /* format "%-15.2f" can be changed */
    iLen = strlen(TruncStr(sBuf));  /* get strlen of after truncated spaces */
    for(i = 0; i < iLen; i ++)
    {
        if(sBuf[i] == '.')
        {
            break;
        }
    }
    iPreLen = i;                    /* get zhiyeeix changdth of "." */

    for(i = 0, j = 0; i < iPreLen; i ++, j ++)
    {
        sOut[j] = sBuf[i];
        if(!i && cNgFg)
        {
            continue;
        }
        if(((iPreLen - i) % 3) == 1 && (iPreLen - i) > 1)
        {
            sOut[++j] = ',';
        }
    }

    for( ; i <= iLen; i ++, j ++)
    {
        sOut[j] = sBuf[i];
    }

    return sOut;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值