Stringstream Noshowpoint 不起作用
stringstream noshowpoint doesn't work
我正试图将67.5写为006750,代码如下:
float price = 67.5
stringstream symbol;
symbol << setfill('0') << setw(6) << fixed << setprecision(2)
<< noshowpoint << price;
但输出为067.50
您感到困惑。std::noshowpoint
只消除整数浮点上的尾随.0
,例如60.0
输出为60
,它并不是简单地去除所有数字上的点。
要得到你想要的,你可以这样做:
float price = 67.5;
std::stringstream symbol;
symbol << std::setfill('0') << std::setw(6) << int(100 * price);
看起来你正试图使用noshowpoint来删除小数,但如果你看看这里的例子,你会发现当pi用noshowpoint打印时,它仍然保留小数,可能是因为没有它你会失去精度。
我可能只是在这里手动操作一些字符串,因为我看到的字符串流选项似乎都不能满足您的要求。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- 我正在开发服务器,ip作为参数传递不起作用