char code TargetYieldBuf[7]; //目标(设定)产量
char code CurrentYieldBuf[7]; //当前产量
char code CompleteRateBuf[6]; //完成率
Uint16 xdata gTrigCnt=0;
unsigned int TargetYield=0;
unsigned int CurrentYield=0;
float CompleteRate;
CurrentYield = gTrigCnt; //触发次数= 当前产量
sprintf(CurrentYieldBuf,"%7x", CurrentYield);
CompleteRate = CurrentYield/gsSetValue.Int; //完成率= 当前产量/目标(设定)产量
sprintf(CompleteRateBuf,"%6x",(unsigned int)CompleteRate);
sprintf(TargetYieldBuf,"%7x", gsSetValue.Int); //目标(设定)产量
问题是1.如何把目标产量的十进制数TargetYield 装换为16进制数后存放到TargetYieldBuf数组中,
2.如何用程序表示完成率,完成率= 当前产量/目标(设定)产量,是sprintf 强制转换是否能达到目的 |