In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the "C++ double type how to retain three decimal places" related knowledge, editor through an actual case to show you the process of operation, the method of operation is simple and fast, practical, I hope this "C++ double type how to retain three decimal places" article can help you solve the problem.
Let me take an example as an example to explain:
Given that the two endpoint coordinates of the line segment are A (xa,ya) and B (xb,yb), the length of the line segment AB is calculated and reserved to 3 places after the decimal point.
Sample input: 1 1
2 2
Sample output: 1.414
The code is as follows: int main (int argc, char** argv) {double xa,ya,xb,yb,result; cin > > xa > > ya > > xb > > yb; result=sqrt ((xb-xa) * (xb-xa) + (yb-ya) * (yb-ya)); coutreturn 0;}
Many people will not understand the following code
Cout
Let's focus on the following:
Set the precision of decimal point
Sets the decimal precision of the floating-point value to be used to format the output operation.
Int main (int argc, char** argv) {double axiom 3.1415926; cout return 0;} that's all for the introduction of "how to keep three decimal places for double types in C++". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.