当前位置:网站首页>Keep valid digits; Keep n digits after the decimal point;
Keep valid digits; Keep n digits after the decimal point;
2022-06-27 15:29:00 【Yang Yi】
Catalog
After decimal point n position
Keep valid numbers
(1)setprecision(n)
- The header file #include<iomanip>
- Specify the total number of display digits for a floating-point number , among n Is the number of digits required ( The sum of the digits before and after the decimal point .), namely Retain n Significant digits ;
- rounding Make a reservation ;
- Not enough significant digits , Can't Make up automatically 0 ( If you want to make up 0 You can add showpoint namely cout<<setprecision(n)<<showpoint<<a; )
- Until the accuracy changes , always Keep the effect
- If the number of digits before the decimal point More than Number of digits to be reserved , Use scientific counting


(2)%g
- Keep valid numbers ; %.6g For the sake of reservation 6 Significant digits .
- If there is a suffix in the decimal part 0, be No output suffix 0;
- The default precision is 6; %g Default hold 6 Significant digits


After decimal point n position
(1)fixed
- You can force numbers to appear in the form of unscientific counting , By default , It can repair the decimal point 6 position ,
- fixed<<setprecision(n) The combination can be kept after the decimal point n position , Can be supplemented automatically 0

(2)%f %lf
- %.2f float The type is reserved after the decimal point 2 position , %.2lf double The type is reserved after the decimal point 2 position
- Not enough digits , It can mend 0

Be careful : Integer operation , If the last output result is decimal , To convert an integer to a floating point number
边栏推荐
- Jupiter core error
- 基于WEB平台的阅读APP设计与实现
- 避孕套巨头过去两年销量下降40% ,下降原因是什么?
- [an Xun cup 2019]attack
- Leetcode 724. Find the central subscript of the array (yes, once)
- Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme
- 注解学习总结
- SQL parsing practice of Pisa proxy
- E-week finance Q1 mobile banking has 650million active users; Layout of financial subsidiaries in emerging fields
- 我想买固收+产品,但是不了解它主要投资哪些方面,有人知道吗?
猜你喜欢

R language error

Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme

Pychart installation and setup

The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
![[high concurrency] deeply analyze the callable interface](/img/24/33c3011752c8f04937ad68d85d4ece.jpg)
[high concurrency] deeply analyze the callable interface

Buuctf Misc

Introduction to TTCAN brick moving

HTTP Caching Protocol practice

QT 如何在背景图中将部分区域设置为透明

阅读别人的代码,是一种怎样的体验
随机推荐
[interview questions] common interview questions (I)
Lei Jun lost another great general, and liweixing, the founding employee of Xiaomi No. 12, left his post. He once had porridge to create Xiaomi; Intel's $5.4 billion acquisition of tower semiconductor
Vscode uses yapf auto format to set the maximum number of characters per line
Professor huangxutao, a great master in CV field, was born at the age of 86. UIUC specially set up a doctoral scholarship to encourage cutting-edge students
可变参数模板 Variadic Templates
Handling methods for NVIDIA deepstream running delay, jamming and crash
CAS之比较并交换
Knightctf 2022 web section
Design of CAN bus controller based on FPGA (with main codes)
Design and implementation of reading app based on Web Platform
All you want to know about large screen visualization is here
Hyperledger Fabric 2. X custom smart contract
[issue 17] golang's one-year experience in developing Meitu
R language error
Atomic operation class
PCL Library - error reporting solution: cmake and Anaconda conflicts during installation
Interpretation of new version features of PostgreSQL 15 (including live Q & A and PPT data summary)
Eolink 推出面向中小企业及初创企业支持计划,为企业赋能!
On traversal of tree nodes
Strong, weak, soft and virtual references of ThreadLocal