Convert a string of the double type into a pure numeric string and a c ++ code with the decimal point. double decimal point

Source: Internet
Author: User

Convert a string of the double type into a pure numeric string and a c ++ code with the decimal point. double decimal point

In today's work, I encountered a string that is not double type converted into a pure word string and a number of int types that indicate the decimal point of this numeric string.

For example, "23.123" --- "23123" + 3 is relatively simple. It is to paste the code here and use it later. You can use it directly.

# Include "stdafx. h"

# Include <stdlib. h>
# Include <iostream>
# Include <string>

Void getInfo (const char * pNum)
{

If (strlen (pNum) = 0)

{

Return;

}


Char num [100] = {0 };
Int index = 0;
Int decemal = 0;
Bool bIsDecemal = false;

// If the variable string is found, it is not stored. But the count starts from decimal.

For (int I = 0; pNum [I]! = '\ 0'; I ++)
{
If (pNum [I] = '.')
{
BIsDecemal = true;
Continue;
}

Num [index] = pNum [I];
Index ++;

If (bIsDecemal)
{
Decemal ++;
}
}

Std: cout <num <"----" <decemal <std: endl;
}

Int _ tmain (int argc, _ TCHAR * argv [])
{
Std: string num = "12.232"; // target 12.232 -- "12232 + 3 Format
GetInfo (num. c_str ());
Getchar ();
Return 0;
}

Related Article

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.