float to string
来源:互联网 发布:js 鼠标点击后div移动 编辑:程序博客网 时间:2024/05/01 00:39
//Warning: if the float variable is negative or larger than the 10000,the decimal part digit will be not precise(but the func logic is correct)!!!
//keep 3 decimal precision digit
int FtoStr(float f, char *str)
{
char buf[20] = {0};
char *pos = buf;
long tmp;
if(NULL == str) return -1;
if(f < 0) {
f = -f;
*str++ = '-';
}
tmp = ((long)(f * 10000) % 10) >= 5 ? (f * 1000) + 1 : (f * 1000);
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;
}
int _tmain(int argc, _TCHAR* argv[])
{
char str[200] = {0};
//float f = 0.23;
float f = 1456.0125678;
FtoStr(f, str);
LogOut("the str is : %s\n", str);
getchar();
}
0 0
- string to float
- float to string
- float to string
- Convert float variable to string
- c# 类型转换string To float
- Bytes to float int String Double
- loadtxt()读取数据类型转换/string转换float/ValueError: could not convert string to float:
- c#中最高效的string to float
- ValueError: could not convert string to float的处理方式
- builtins.ValueError: could not convert string to float:的问题
- String转Float问题
- float、int、string转换
- string转换float
- string转float
- 使用python中的numpy模块遇到could not convert string to float
- Python TypeError: coercing to Unicode: need string or buffer, float found
- [Scala--基础]--->类型转换(String to Double 、Long、Float和Int)
- float chang to bytes
- 在MyEclipse中设置jsp页面为默认utf-8编码
- struts2登陆拦截器
- JAVA虚拟机生命周期
- LeetCode之Binary Tree Preorder Traversal
- RGB图像转为灰度图
- float to string
- 删除共享
- spring hibernate 整合+项目框架搭建 包含详细注释(清华大学各系统使用代码)
- Xcode离线帮助文档的安装
- LeetCode(98) Validate Binary Search Tree
- html 图片 地图映射
- 设置MyEclipse开发项目时使用的JDK
- java代理模式
- 【UILabel和UIButton】