纯整数运算,需要注意是否会溢出(貌似T1也不足以让其溢出) 。
int vol_format(char rsb[],char T1,char T2,char T3,char T4)
{
int index;
uint32 v;
v = T1;
v = (v * 10) + T2;
v = (v * 10) + T3;
v = (v * 10) + T4;
index = 0;
for(v *= 83; v > 0; v /= 10){
rsb[index++] = (v % 10) + '0';
if(4 == index){
rsb[index++] = '.';
}
}
if(index <= 4){
while(index < 4){
rsb[index++] = '0';
}
rsb[index++] = '.';
}
if(index <= 5){
rsb[index++] = '0';
}
sm_memreverse(rsb,index);
rsb[index] = '\0';
return(index);
}
|