Output decimal Format control in C + + (how to control the number of digits in C + + that are exported after a floating-point decimal point)

Source: Internet
Author: User

First you need to have #include<iomanip> this header file because it is the input output stream format control

Second such as Double sum=10; Cout<<setiosflags (ios::fixed) <<setprecision (1) <<sum;

where Setiosflags (ios::fixed) do not write wrong it with the back of the Setprecision (1) used to control the output decimal point after the number of digits, that is, a bit 10.0;

If only setprecision (1) represents a decimal 1e+001 with a valid number;

cout<< setiosflags (ios::fixed) << setprecision (2) << setiosflags (ios::left) << SETW (+) < < string<< ' a ';//left-aligned, then output the character ' a ' after starting at the 40th position of the string's first letter. In addition the control decimal place is two bits.

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.