1 Star 0 Fork 8

thineagle/Xipkpublib_Update

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GetChineseNumber.c 2.54 KB
一键复制 编辑 原始数据 按行查看 历史
suitianmou 提交于 2016-03-17 14:03 . ʼ1.2汾
/*******************************************************
* 公 司: 大连同方软银科技有限公司
* 程 序 名: GetChineseNumber.c
* 程序功能: 转换数字为中文
* 输入参数:
* number 要转换的数据
* 输出参数:
* 返 回 值:
* 转换后中文
* 作 者: yangwc
* 开发日期: 2007/1
* 修 改 人:
* 修改日期:
*******************************************************/
#include "kernel/syspub.h"
char *GetChineseNumber(double number)
{
char *upnum[10] = {"零","壹","贰","叁","肆","伍","陆","柒","捌","玖", };
char *unit[15]= {"整", "分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", };
short limit[] = {14, 1, 2, 14, 4, 5, 6, 10, 8, 9, 10, 14, 12, 13, 14};
double fje;
short i, j, k, lim;
char *str, *str3, *str2, *wrstr;
char *p, str1[36];
fje = number;
if (fje < 0)
{
number = (-1) * number;
}
str = (char *)malloc(30);
str2 = (char *)malloc(3);
str3 = (char *)malloc(30);
wrstr = (char *)malloc(60);
sprintf(str, "%.2f", number);
i = 0;
j = k = strlen(str);
for(i = 0; i < j; i++)
{
if (str[i] == '.')
{
k = i;
break;
}
}
strncpy(str3, str, k);
str3[k] = '\0';
strncpy(str2, str+k+1, 2);
str2[2] = '\0';
strcat(str3, str2);
strcpy(str, str3);
k = k + 2;
if (k > 14)
{
free(str);
free(wrstr);
return((char *)0);
}
strcpy(wrstr, "");
j = 0;
lim = k;
for(i = k; i > 0; i--)
{
if (str[k-i] > '0')
{
if (lim > i+1)
strcat(wrstr, upnum[0]);
strcat(wrstr, upnum[str[k-i] - '0']);
strcat(wrstr, unit[i]);
lim = i;
}
else
if (lim <= limit[i])
strcat(wrstr, unit[i]);
}
/*********GL:整添加到角以前,不到分*********/
sprintf(str1, "%lf", number);
p = strchr(str1, '.');
p += 2;
if (*p == '0') strcat(wrstr, unit[0]);
/*************************/
/*free(str);*/
/*********yud:如果小于零,去掉圆字******/
if (number < 1.00 && number > 0.10)
{
strncpy(str1, wrstr+2, 8);
strcpy(wrstr, str1);
}
if (number < 0.10)
{
strncpy(str1, wrstr+4, 6);
strcpy(wrstr, str1);
}
if (fje == 0.00)
{
strcpy(str1, "零圆整");
strcpy(wrstr, str1);
}
/***************************************/
/*** add by icesky @20150402*/
free(str);
free(str2);
free(str3);
/*** add by icesky @20150402*/
return(wrstr);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/thineagle/Xipkpublib_Update.git
git@gitee.com:thineagle/Xipkpublib_Update.git
thineagle
Xipkpublib_Update
Xipkpublib_Update
master

搜索帮助