在gcc中使用printf控制浮点数的指数位数
Control exponent digits of a float using printf in gcc
我使用mingw-gcc
,我想打印一个float
。
#include <cstdio>
#include <iostream>
int main(){
float a =1.23;
std::cout << std::scientific << a << std::endl;
printf("%en",a);
return 0;
}
输出为
1.230000e+000
1.230000e+000
但是float不需要超过两位数字。是否有任何方法在gcc
出口数字与2位指数?
1.230000e+00
1.230000e+00
是否有类似的功能像Visual studio的_set_output_format ?
至少就printf
而言,似乎可以将环境变量PRINTF_EXPONENT_DIGITS
设置为2
并使用-posix
开关进行编译(在干净安装的Windows 10上使用mingwg++ 5.3.0进行测试)
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 使用提升将数据从 PyObject 复制到浮点数 *
- 使用浮点数和双精度数的非常小数字的数学
- 使用英特尔内联函数将打包的 8 位整数乘以浮点数向量
- 如何在 c++ 中将小数点后两位数的浮点数分配给另一个浮点数
- 返回浮点数的小数位数
- txt 文件中浮点数的最大和最小值
- 为什么 std::cout 打印浮点数、双精度和长双精度到相同的小数精度?
- 将浮点数转换为无符号字符数组并打印出来
- 如何将时间字符串 (M:SS) 转换为浮点数
- 如何将浮点数(*)[6]转换为浮点**类型?
- C++将浮点数乘以分数
- 如何将浮点数转换为uint8_t?
- 在 C/C++ 中以指数形式将浮点数声明为宏的正确方法是什么?
- 输出浮点数为三位或更多,以避免指数
- 如何在 c++ 下对尾数和双精度或浮点数的指数部分进行操作(快速)
- 在gcc中使用printf控制浮点数的指数位数
- 从符号尾数和指数构造浮点数