标签:长度 str -- char get printf break value print
char* GetDoubleStr(double value) { char buf[32]={0};//长度可以自定义 sprintf(buf,"%.8f",value);//保留8位小数,不够补0 int index = 0; int len = strlen(buf); for(int i = len-1;i>0;i--) { if(buf[i] == ‘0‘) continue; else { if(buf[i] == ‘.‘) index = i; else index = i+1; break; } } buf[index] = ‘\0‘; return buf; }
C语言下double转char*或者std::string,可以精确转换不含多余的0
标签:长度 str -- char get printf break value print
原文地址:http://www.cnblogs.com/zhmf-4459/p/6126648.html