c++boost格式float-如何指定我不想要的.以及后面的零
c++ boost format float - how to specify that I do not want . and following zeros
我想使用boost::format
将浮点数转换为字符串。以下是预期结果的几个例子:
0.5 -> "0.5"
0 -> "0"
1.00001 -> "1"
3.66 -> "3.7"
我目前正在使用
boost::format("%1$.1f")
它基本上是有效的,但当我想要"0"
和"1"
时,0
的结果是"0.0"
,1.00001
是"1.0"
。
为了摆脱毫无意义的.0
,我需要更改什么?
使用条件在两种格式之间进行选择。
boost::format(abs(x-floor(x+0.05)) < 0.1 ? "%1$.0f" : "%1$.1f")
相关文章:
- 如何在openssl-ecc中获取十六进制格式的私钥
- 将"打开的CV图像"中的"颜色"转换为整数格式
- TDateTime格式在C++Builder中不会更改
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 检查不带转换的扫描格式
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- 是否可以从格式字符串中检索"width"
- clang格式:宏的缩进
- clang格式:禁用排序包含
- 在用于格式4的arm模拟器中实现功能时的一个问题
- 将RGB图像保存为PPM格式
- 询问在设计我的手臂模拟器功能表示格式1
- 当使用比格式支持的精度更高的精度来显示数字时,会写出什么数据
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 如何将strftime中的格式错误作为异常捕获
- 在C++/Visual Studio中,通过给定数据格式(doubles、float、int、1位bools)的UDP发
- c++boost格式float-如何指定我不想要的.以及后面的零
- Qt - 格式 '%f' 需要类型为 'float*' 的参数,但参数 2 的类型为 'double' ^
- (程序设计语言C/C++)中的格式值类型float
- 视觉C++:"float"的 printf() 格式规范是什么?