MFC uses the CString and format member functions to format the output of a number

Source: Internet
Author: User
Tags value of pi

Str. Format ("Formatting control string", output list);

The format control string consists of a format string and a non-formatted string enclosed in double quotation marks. Where the non-format string is output as-is.

A format string is a string that begins with a%:%[identifier [output min width] [precision] conversion specifier.

Common conversion specifiers: D, integral type, f, floating point, double precision, E, exponential output, double precision, s, output string, parameter char* pointer, etc.

[] can be omitted within.

The logo has-, +:-Indicates left alignment, right fill, and vice versa.

Outputs the minimum width, expressed in decimal integers.

The precision, beginning with the. Number, followed by a decimal integer. The meaning is that if the output is a number, the number of decimal places, or if the output is a character, the number of characters in the output.

With the _ttof () function, you need to include the Stdlib.h file to convert the CString type to floating-point data.

1 double PI =3.14159;

2 CString s;

3 S.format (" output with fractional form:%.2f", pi);//So, the value of pi is stored in S, it's character type.

4 PPI = _ttof ((LPCSTR) s);//So, we keep pi=3.14159 to two decimal places.

MFC uses the CString and format member functions to format the output of a number

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.