#include "stdafx.h" #include "stdlib.h"
char *F2S(double d, char* str) { char str1[40]; int j=0,k,i; i = (int)d; //浮点数的整数部分 //d = d-(int)d; while(i>0) { str1[j++] = i%10+'0'; i /= 10; } for(k=0;k<j;k++) str[k] = str1[j-1-k]; //
str[j++] = '.'; d -= (int)d; for(i=0;i<10;i++) { d *= 10; str[j++] = (int)d+'0'; d -= (int)d; } while(str[--j]=='0'); str[++j] = '\0'; return str; }
int _tmain(int argc, _TCHAR* argv[]) { double d = 365.897003120000; char str[20]; char *p = F2S(d, str); printf("%s\n",str); printf("%s\n",p);
return 0; } |