/*========================================================================
=给金额字段加千位分隔符 =
========================================================================*/
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;
}