How to avoid automatic conversion from a C ++ floating point to a string into a scientific notation?

Source: Internet
Author: User

Functions _ gcvt and _ gcvt_s can convert floating point numbers to strings. I have a limit in http://blog.csdn.net/master_feng2009/article/details/9446355.

However, when the floating point number is an infinite decimal number, the conversion to a string may automatically become a scientific notation, and in some cases, it should not be converted to a scientific or technical method, such as executing an SQL statement, when floating point data is inserted, an error occurs if it is a scientific counting rule.

So how can we avoid automatic conversion to scientific notation? The following method can be used:

Double dprecision;

Dprecision = 0.06666666666666;

_ Gcvt_s (carray, dprecision, 20); // The output result is 6.66666666660004e-002.

Ostrstreamos;

Istreamin (OS. rdbuf ());

OS <Endl;

OS <dprecision;

OS <ends;

In> carray; // result, 0.0666667, not scientific notation

 

Note: The header file must be included.# Include
<Strstream>.

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.