/*
* Function Name: edit_money
* Description : 编辑数值金额成中文金额
* Input : char * in -- 输入的数值字符串
*
* Output : char * out -- 输出的中文金额
* Return :
*/
void
edit_money( char * in, char * out )
{
char s1[256], s2[ 10 ];
int i, j, k, l, n, len1;
char * p_dot;
char chn_digit[11][3] = { "零", "壹", "贰", "叁", "肆", "伍",
"陆", "柒", "捌", "玖" };
char chn_unit1[4][3] = { "", "拾", "佰", "仟" };
char chn_unit2[3][5] = { "万", "亿", "万亿" };
if ( in == NULL || out == NULL )
return;
if ( strlen( in ) == 0 )
return;
memset(s1,0x00,sizeof(s1));
strncpy( s1, in, sizeof(s1) );
/*判断是否有小数点*/
p_dot = strchr( s1, '.' );
if ( p_dot == NULL )
s2[0] = 0x0;
else
{
memset(s2,0x00,sizeof(s2));
strcpy( s2, p_dot + 1 );
*p_dot = 0x0;
}
/*
* 转换为中文
*/
out[0] = 0x0;
len1 = strlen( s1 );
n = ( len1 - 1 ) / 4 + 1;
l = 0;
for ( i = 0; i < n; i++ )
{
if ( i == 0 )
k = len1 - 4 * ( n - 1 );
else
k = 4;
for ( j = 0; j < k; j++, l++ )
{
if ( s1[ l ] == '0' &&
( ( j + 1 < k && s1[ l+1 ] == '0' ) ||
j + 1 == k ) )
continue;
/* 100000.00显示为:壹拾万元 */
strcat( out, chn_digit[ s1[ l ] - '0' ] );
if ( s1[ l ] != '0' )
strcat( out, chn_unit1[ k - j - 1 ] );
}
/* 20030921 modify:(4*i -> l-k), add:(i==0)
if ( i < n - 1 && memcmp( s1 + 4*i, "0000", k ) != 0 )
strcat( out, chn_unit2[ n - i - 2 ] );
*/
if( ( i < n - 1 ) && \
( i == 0 || memcmp( s1+l-k, "0000", k ) != 0 ) )
strcat( out, chn_unit2[ n - i - 2 ] );
}
if ( strlen( out ) != 0 )
strcat( out, "元" );
if ( atoi( s2 ) == 0 )
strcat( out, "整" );
else
{
/* 个位是零或角位是零, 20030921 add:(s2[0] == '0' ) */
if( ( len1 > 1 && s1[ len1 - 1 ] == '0' ) \
|| s2[0] == '0' )
strcat( out, "零" );
if ( s2[0] != '0' )
{
strcat( out, chn_digit[ s2[0] - '0' ] );
strcat( out, "角" );
}
if ( s2[1] != '0' && s2[1] != 0 )
{
strcat( out, chn_digit[ s2[1] - '0' ] );
strcat( out, "分" );
}
}
return;
}
阅读(2662) | 评论(0) | 转发(0) |