先看下我的代码
ofstream mcfile; //创建对象
mcfile.open(tfwpathAuto); //创建文件
mcfile << pixel_x << endl;
mcfile << pixel_y << endl;
mcfile.close();
tfwpathAuto是我新建文件的路径以及文件名,比如C:\\111.tfw;
pixel_x和pixel_y是我要写进去的数值,float型
假如pixel_x = 40545678,写进文件就变成了4.05456e+007,
现在我不想用科学计数法
求指教~~~
c ,科学计数法
------解决方案--------------------------------------------------------
输出之前设置一下
mcfile << std::fixed;
------解决方案--------------------------------------------------------
楼上正解!
------解决方案--------------------------------------------------------
string StringCast(int source)
{
std::stringstream ss;
ss << source;
return ss.str();
}
------解决方案--------------------------------------------------------
不知道你在说什么,数字类型哪来的逗号啊。下面是个例子,你看看能不能变成你需要的吧。
#include <limits>
#include <iostream>
int main ()
{
float const a = std::numeric_limits<float>::max();
std::cout << std::fixed;
std::cout.precision(0);
std::cout << a << std::endl;
return 0;
}
------解决方案--------------------------------------------------------
关键是float变量只能保存最长十进制有效数字6位啊!
参考include\float.h
...
#define DBL_DIG 15 /* # of decimal digits of precision */
#define DBL_EPSILON 2.2204460492503131e-016 /* smallest such that 1.0+DBL_EPSILON != 1.0 */
#define DBL_MANT_DIG 53 /* # of bits in mantissa */
#define DBL_MAX 1.7976931348623158e+308 /* max value */
#define DBL_MAX_10_EXP 308 /* max decimal exponent */
#define DBL_MAX_EXP 1024 /* max binary exponent */
#define DBL_MIN 2.2250738585072014e-308 /* min positive value */
#define DBL_MIN_10_EXP (-307) /* min decimal exponent */
#define DBL_MIN_EXP (-1021) /* min binary exponent */