Use of fixed and setprecision

Source: Internet
Author: User
// Manipulators (Stream operator) // detailed parsing // use of stream operator fixed and setprecision # include <iostream> # include <iomanip> using namespace STD; int main () {double num = 123.45678; // by default, the maximum number of digits (including before and after the decimal point) displayed in the data is 6 digits, rounded to five. Cout <num <Endl; // setprecision indicates that the number of digits is 7 bits. Therefore, the cout number is rounded to <setprecision (7) <num <Endl; // If fixed is placed before setprecision, setprecision (2) specifies the number of digits to display after the decimal point. cout <fixed <setprecision (2) <num <Endl; return 0 ;}

Output result:
123.457
123.4568
123.46

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.