当前位置:网站首页>你不知道的stringstream的用法
你不知道的stringstream的用法
2022-06-13 08:51:00 【刀么克瑟拉莫】
- 保留两位小数并保存到字符串
- stringstream和iostream的用法很相似
#include <sstream>
#include <iomanip>
#include <iostream>
using namespace std;
int main(int argc, char **argv) {
double a = 0.13567;
stringstream ss;
ss << fixed << setprecision(2) << a;
ss >> a; //保存到double
cout << ss.str() << endl; //0.14
return 0;
}
- 自己实现保留两位小数并保存到字符串
- 注意:+=比+快
string KeepTwo(double a) {
int b = a * 100 + 0.5;
string s;
s += to_string(b/100) + ".";
b %= 100;
if( b < 10) {
s += "0";
}
s += to_string(b);
return s;
}
边栏推荐
- Explanation of JS event loop mechanism and asynchronous tasks
- Logstash configuration reference article
- redis. exceptions. ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.
- Namespace in TS (2)
- Form exercise 2
- ES6 module import / export summary
- 顺时针打印个数组
- Uni app essay
- 4、 Js-es5-i / O
- Taobao commodity sales interface / Taobao commodity sales monitoring interface / cumulative commodity sales interface
猜你喜欢

【安全】零基础如何从0到1逆袭成为安全工程师

Form exercise 2

Screenshot of cesium implementation scenario

JS - print 99 multiplication table of the for cycle case

1. Learning sequence of SolidWorks modules

redis.exceptions.ConnectionError: Error 111 connecting to 172.16.8.128:6379. Connection refused.

Browser render passes

useRoutes() may be used only in the context of a <Router> component.

Differences and uses among cookies, localstorage, sessionstorage, and application caching

Yarn package management tool
随机推荐
【网络安全渗透】如果你还不懂CSRF?这一篇让你彻底掌握
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
抖音关键词搜索列表接口,超详细的接口对接步骤
JS - print 99 multiplication table of the for cycle case
How to resolve "the operation cannot be completed successfully because the file contains viruses or potentially junk software
银行理财产品有哪些?清算期是多长?
Filebeat collects logs to elk
File upload JS
Common network problems and troubleshooting methods of gbase
8、 JS data type conversion
Diversified tables through TL table row consolidation
JS - set countdown for Date object case
0.一些自己初学Solidworks的疑惑
情绪处理技巧
5、 Constant, variable
Logstash configuration reference article
JS string method
PHP wechat special merchant incoming V3 packaging interface
2021-04-16
Replace jade engine with EJS