Convert float variable to string
来源:互联网 发布:linux下gcc编译器 编辑:程序博客网 时间:2024/05/01 01:34
//Warning: if the float variable is larger than the 10000,the decimal part digit will be not precise(but the func logic is correct)!!!
int FtoStr(float f, char *str)
{
char buf[20] = {0};
char *pos = buf;
int tmp;
if(NULL == str) return -1;
if(f < 0) {
f = -f;
*str++ = '-';
}
tmp = ((int)(f * 10000) % 10) >= 5 ? (f * 1000) + 1 : (f * 1000); //keep 3 decimal precision digit
do {
if(pos == buf + 3)//insert the decimal point position
*pos++ = '.';
*pos++ = tmp % 10 + '0';
}while(tmp /= 10);//check whether the copied char is the last char or not
while(pos < buf + 3)//less than 1.0
*pos++ = '0';
if(pos == buf + 3){
*pos++ = '.';
*pos++ = tmp +'0';
}
while(pos > buf)
*str++ = *--pos;
*str = '\0';
return 0;
}
0 0
- Convert float variable to string
- ValueError: could not convert string to float的处理方式
- builtins.ValueError: could not convert string to float:的问题
- loadtxt()读取数据类型转换/string转换float/ValueError: could not convert string to float:
- string Convert To XML
- CONVERT to String
- Convert String to Stream
- Convert String to Stream
- json convert to string
- 使用python中的numpy模块遇到could not convert string to float
- string to float
- float to string
- float to string
- How to convert InputStream to String/convert char[] to String
- SQL CONVERT FUNCTION CONVERT DATETIME TO STRING
- C++ convert int to string
- convert a string to XmlElement
- Convert From BSTR to String
- 黑马程序员——高新技术---反射
- Java Exception
- 【grunt整合版】30分钟学会使用grunt打包前端代码
- 技术面试中关于你所作的项目的常见行为类问题
- UIImageView 使用
- Convert float variable to string
- 再学Java I/O系统
- 使用GruntJS构建Web程序 (1)
- 怎么在windows下安装grunt
- [转]CENTOS 6.x INTEL集成显示驱动加载错误的解决办法
- 黑马程序员_网络编程
- NSTimer 使用
- PHP实现文件的下载
- Object-C中的“反射”