网上的都是没有用的,没办法,只能自己手撸一个:
void myPrintf222(float fVal_In,char *pchar) { char result[arrLen]={0}; int decVal; float dotNum;
decVal = fVal_In;
dotNum= fVal_In-decVal;
int nums=0;
for(int i=0;i< 20;i++)
{
if(decVal>=100000)
{
int tempval= decVal/100000;
decVal-=100000*tempval;
result[nums]=tempval+48;
nums++;
}
else if(decVal>=10000)
{
int tempval= decVal/10000;
decVal-=10000*tempval;
result[nums]=tempval+48;
nums++;
}
else if(decVal>=1000)
{
int tempval= decVal/1000;
decVal-=1000*tempval;
result[nums]=tempval+48;
nums++;
}
else if(decVal>=100)
{
int tempval= decVal/100;
decVal-=100*tempval;
result[nums]=tempval+48;
nums++;
}
else if(decVal>=10)
{
int tempval= decVal/10;
decVal-=10*tempval;
result[nums]=tempval+48;
nums++;
}
else if(decVal>=1)
{
int tempval= decVal;
decVal-=1*tempval;
result[nums]=tempval+48;
nums++;
break;
}
}
#if 0 if(dotNum>=0.00001) { result[nums]=46; nums++; }
for(int k=0;k<5;k++)
{
if(dotNum>=0.1)
{
int tempval= dotNum*10;
dotNum= dotNum*10-tempval;
result[nums]=tempval+48;
nums++;
}
}
#endif
#if 1
if(dotNum>=0.1)
{
int tempval= dotNum*10;
dotNum= dotNum*10-tempval;
result[nums]=tempval+48;
nums++;
}
#endif
memcpy(pchar,result,strlen(result) );
printf(result);
}
|