y**i 发帖数: 1112 | 1 小数部分是不是可以这么做?
float a = 12345.67;
float foa = a-(int)a;
const int nfoa = 2;
char szfoa[nfoa+1];
memset(szfoa, 0, nfoa+1);
for (int i = 0; i < nfoa; ++i)
{
foa *= 10;
szfoa[i] = '0'+(int)foa;
foa -= (int)foa;
}
if ((int)(foa*10) > 4)
++szfoa[nfoa-1];
345.67 |
|