当前位置:网站首页>You don't know the usage of stringstream
You don't know the usage of stringstream
2022-06-13 08:52:00 【Knife, kesselamo】
- Keep two decimal places and save to string
- stringstream and iostream The usage of is very similar
#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; // Save to double
cout << ss.str() << endl; //0.14
return 0;
}
- Own implementation to retain two decimal places and save to the string
- Be careful :+= Than + fast
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;
}
边栏推荐
- Filebeat collects logs to elk
- JS array using the reduce() method
- Can I open an account for the reverse repurchase of treasury bonds? Can I directly open the security of securities companies on the app for the reverse repurchase of treasury bonds? How can I open an
- GBase 8a V95与V86压缩策略类比
- 容器概念和云原生
- MySQL 8.0 modifying SQL_ mode=only_ full_ group_ by
- 1、 JS introduction
- 1.SolidWorks各模块的学习顺序
- Taobao commodity sales interface / Taobao commodity sales monitoring interface / cumulative commodity sales interface
- Invalid flex layout setting width
猜你喜欢

Cesium displays a pop-up box at the specified position and moves with the map

À propos des principes de chiffrement et de décryptage RSA

Container concept and cloud native

Screenshot of cesium implementation scenario

Knowledge points related to system architecture 1

Docker installing MySQL local remote connection docker container MySQL

CentOS installing MySQL and setting up remote access

网络安全漏洞分析之重定向漏洞分析

Yarn package management tool

centos 安装mysql及设置远程访问
随机推荐
[leetcode weekly race record] record of the 80th biweekly race
regular expression
Is it safe to open an account online? Can a novice open an account?
JS ask for the day of the year
Common network problems and troubleshooting methods of gbase
Knowledge points related to system architecture 1
Yarn package management tool
Software Architecture Overview knowledge
GBase 8a磁盤問題及處理
JS array method
JS - set countdown for Date object case
ERP outlet
[pychart pit stepping record] prompt after configuring remote operation, [errno 2] no such file or directory
Basic use of cesium, including loading images, terrain, models, vector data, etc
0. Quelques doutes au sujet de SolidWorks
關於RSA加密解密原理
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
Custom exception class myexception
「解读」华为云桌面说“流畅”的时候,究竟在说什么?
1. preliminary understanding of Express